From 79eebec218add332ffdd88f978437ce6f85c99f3 Mon Sep 17 00:00:00 2001 From: "nhotta%netscape.com" Date: Wed, 14 Jul 1999 16:53:17 +0000 Subject: [PATCH] Bug 9229, added PRTime support. git-svn-id: svn://10.0.0.236/trunk@39288 18797224-902f-48f8-a5cc-f745e15eee43 --- .../intl/locale/public/nsIDateTimeFormat.h | 31 +++++++++++++---- .../locale/src/mac/nsDateTimeFormatMac.cpp | 33 +++++++++++++++++-- .../intl/locale/src/mac/nsDateTimeFormatMac.h | 15 ++++++++- .../locale/src/unix/nsDateTimeFormatUnix.cpp | 30 +++++++++++++++++ .../locale/src/unix/nsDateTimeFormatUnix.h | 16 ++++++++- .../src/windows/nsDateTimeFormatWin.cpp | 30 +++++++++++++++++ .../locale/src/windows/nsDateTimeFormatWin.h | 16 ++++++++- 7 files changed, 159 insertions(+), 12 deletions(-) diff --git a/mozilla/intl/locale/public/nsIDateTimeFormat.h b/mozilla/intl/locale/public/nsIDateTimeFormat.h index 0c8364f1c21..95b5f59ad2d 100644 --- a/mozilla/intl/locale/public/nsIDateTimeFormat.h +++ b/mozilla/intl/locale/public/nsIDateTimeFormat.h @@ -24,6 +24,7 @@ #include "nscore.h" #include "nsString.h" #include "nsILocale.h" +#include "prtime.h" #include @@ -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__ */ diff --git a/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.cpp b/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.cpp index c9e20df9d98..44ef1431b15 100644 --- a/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.cpp +++ b/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.cpp @@ -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); +} + diff --git a/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.h b/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.h index 878d5f06c85..9d6f6e89e8e 100644 --- a/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.h +++ b/mozilla/intl/locale/src/mac/nsDateTimeFormatMac.h @@ -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__ */ diff --git a/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.cpp b/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.cpp index dc663ff1d54..6e2ae82a1c6 100644 --- a/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.cpp +++ b/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.cpp @@ -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); +} + diff --git a/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.h b/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.h index a6447bf1884..deac56f35a8 100644 --- a/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.h +++ b/mozilla/intl/locale/src/unix/nsDateTimeFormatUnix.h @@ -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__ */ diff --git a/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.cpp b/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.cpp index 9df07164eda..10d78bffc49 100644 --- a/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.cpp +++ b/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.cpp @@ -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 diff --git a/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.h b/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.h index c169c1484e6..0ccc811d5fd 100644 --- a/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.h +++ b/mozilla/intl/locale/src/windows/nsDateTimeFormatWin.h @@ -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