Bug 9229, added PRTime support.
This commit is contained in:
Родитель
e0d2cedb5d
Коммит
f2e27b8029
|
@ -24,6 +24,7 @@
|
|||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsILocale.h"
|
||||
#include "prtime.h"
|
||||
#include <time.h>
|
||||
|
||||
|
||||
|
@ -32,21 +33,23 @@
|
|||
{ 0x2bbaa0b0, 0xa591, 0x11d2, \
|
||||
{ 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
|
||||
|
||||
typedef enum {
|
||||
kDateFormatNone, // do not include the date in the format string
|
||||
typedef PRInt32 nsDateFormatSelector;
|
||||
enum {
|
||||
kDateFormatNone = 0, // do not include the date in the format string
|
||||
kDateFormatLong, // provides the long date format for the given locale
|
||||
kDateFormatShort, // provides the short date format for the given locale
|
||||
kDateFormatYearMonth, // formats using only the year and month
|
||||
kDateFormatWeekday // week day (e.g. Mon, Tue)
|
||||
} nsDateFormatSelector;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
kTimeFormatNone, // don't include the time in the format string
|
||||
typedef PRInt32 nsTimeFormatSelector;
|
||||
enum {
|
||||
kTimeFormatNone = 0, // don't include the time in the format string
|
||||
kTimeFormatSeconds, // provides the time format with seconds in the given locale
|
||||
kTimeFormatNoSeconds, // provides the time format without seconds in the given locale
|
||||
kTimeFormatSecondsForce24Hour, // forces the time format to use the 24 clock, regardless of the locale conventions
|
||||
kTimeFormatNoSecondsForce24Hour // forces the time format to use the 24 clock, regardless of the locale conventions
|
||||
} nsTimeFormatSelector;
|
||||
};
|
||||
|
||||
|
||||
// Locale sensitive date and time format interface
|
||||
|
@ -54,7 +57,7 @@ typedef enum {
|
|||
class nsIDateTimeFormat : public nsISupports {
|
||||
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDATETIMEFORMAT_IID; return iid; }
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDATETIMEFORMAT_IID)
|
||||
|
||||
// performs a locale sensitive date formatting operation on the time_t parameter
|
||||
NS_IMETHOD FormatTime(nsILocale* locale,
|
||||
|
@ -69,6 +72,20 @@ public:
|
|||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const struct tm* tmTime,
|
||||
nsString& stringOut) = 0;
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
NS_IMETHOD FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut) = 0;
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
NS_IMETHOD FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIDateTimeFormat_h__ */
|
||||
|
|
|
@ -239,8 +239,6 @@ nsresult nsDateTimeFormatMac::FormatTMTime(nsILocale* locale,
|
|||
NS_ASSERTION(tmTime->tm_sec >= 0, "tm is not set correctly");
|
||||
NS_ASSERTION(tmTime->tm_wday >= 0, "tm is not set correctly");
|
||||
|
||||
// Mac need a number from 1904 to 2040
|
||||
// tm only provide the last two digit of the year */
|
||||
macDateTime.year = tmTime->tm_year + 1900;
|
||||
|
||||
// Mac use 1 for Jan and 12 for Dec
|
||||
|
@ -362,3 +360,34 @@ nsresult nsDateTimeFormatMac::FormatTMTime(nsILocale* locale,
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
nsresult nsDateTimeFormatMac::FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
PRExplodedTime explodedTime;
|
||||
PR_ExplodeTime(prTime, PR_LocalTimeParameters, &explodedTime);
|
||||
|
||||
return FormatPRExplodedTime(locale, dateFormatSelector, timeFormatSelector, &explodedTime, stringOut);
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
nsresult nsDateTimeFormatMac::FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
struct tm tmTime;
|
||||
tmTime.tm_mon = explodedTime->tm_month;
|
||||
tmTime.tm_mday = explodedTime->tm_mday;
|
||||
tmTime.tm_hour = explodedTime->tm_hour;
|
||||
tmTime.tm_min = explodedTime->tm_min;
|
||||
tmTime.tm_sec = explodedTime->tm_sec;
|
||||
|
||||
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, &tmTime, stringOut);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,21 @@ public:
|
|||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const struct tm* tmTime,
|
||||
nsString& stringOut);
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
NS_IMETHOD FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatMac() {NS_INIT_REFCNT();};
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
NS_IMETHOD FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatMac() {NS_INIT_REFCNT();}
|
||||
};
|
||||
|
||||
#endif /* nsDateTimeFormatMac_h__ */
|
||||
|
|
|
@ -167,3 +167,33 @@ nsresult nsDateTimeFormatUnix::FormatTMTime(nsILocale* locale,
|
|||
return res;
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
nsresult nsDateTimeFormatUnix::FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
PRExplodedTime explodedTime;
|
||||
PR_ExplodeTime(prTime, PR_LocalTimeParameters, &explodedTime);
|
||||
|
||||
return FormatPRExplodedTime(locale, dateFormatSelector, timeFormatSelector, &explodedTime, stringOut);
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
nsresult nsDateTimeFormatUnix::FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
struct tm tmTime;
|
||||
tmTime.tm_mon = explodedTime->tm_month;
|
||||
tmTime.tm_mday = explodedTime->tm_mday;
|
||||
tmTime.tm_hour = explodedTime->tm_hour;
|
||||
tmTime.tm_min = explodedTime->tm_min;
|
||||
tmTime.tm_sec = explodedTime->tm_sec;
|
||||
|
||||
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, &tmTime, stringOut);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,21 @@ public:
|
|||
const struct tm* tmTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatUnix() {NS_INIT_REFCNT();};
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
NS_IMETHOD FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut);
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
NS_IMETHOD FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatUnix() {NS_INIT_REFCNT();}
|
||||
};
|
||||
|
||||
#endif /* nsDateTimeFormatUnix_h__ */
|
||||
|
|
|
@ -184,6 +184,36 @@ nsresult nsDateTimeFormatWin::FormatTMTime(nsILocale* locale,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
nsresult nsDateTimeFormatWin::FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
PRExplodedTime explodedTime;
|
||||
PR_ExplodeTime(prTime, PR_LocalTimeParameters, &explodedTime);
|
||||
|
||||
return FormatPRExplodedTime(locale, dateFormatSelector, timeFormatSelector, &explodedTime, stringOut);
|
||||
}
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
nsresult nsDateTimeFormatWin::FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
struct tm tmTime;
|
||||
tmTime.tm_mon = explodedTime->tm_month;
|
||||
tmTime.tm_mday = explodedTime->tm_mday;
|
||||
tmTime.tm_hour = explodedTime->tm_hour;
|
||||
tmTime.tm_min = explodedTime->tm_min;
|
||||
tmTime.tm_sec = explodedTime->tm_sec;
|
||||
|
||||
return FormatTMTime(locale, dateFormatSelector, timeFormatSelector, &tmTime, stringOut);
|
||||
}
|
||||
|
||||
nsresult nsDateTimeFormatWin::ConvertToUnicode(const char *inString, const PRInt32 inLen, PRUnichar *outString, PRInt32 *outLen)
|
||||
{
|
||||
// convert result to unicode
|
||||
|
|
|
@ -45,7 +45,21 @@ public:
|
|||
const struct tm* tmTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatWin() {NS_INIT_REFCNT();};
|
||||
// performs a locale sensitive date formatting operation on the PRTime parameter
|
||||
NS_IMETHOD FormatPRTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRTime prTime,
|
||||
nsString& stringOut);
|
||||
|
||||
// performs a locale sensitive date formatting operation on the PRExplodedTime parameter
|
||||
NS_IMETHOD FormatPRExplodedTime(nsILocale* locale,
|
||||
const nsDateFormatSelector dateFormatSelector,
|
||||
const nsTimeFormatSelector timeFormatSelector,
|
||||
const PRExplodedTime* explodedTime,
|
||||
nsString& stringOut);
|
||||
|
||||
nsDateTimeFormatWin() {NS_INIT_REFCNT();}
|
||||
|
||||
private:
|
||||
// util function to call unicode converter
|
||||
|
|
Загрузка…
Ссылка в новой задаче