diff options
author | blythe%netscape.com <devnull@localhost> | 2002-02-08 00:40:26 +0000 |
---|---|---|
committer | blythe%netscape.com <devnull@localhost> | 2002-02-08 00:40:26 +0000 |
commit | 23ce721903fe29d95f36d63bc90b45cdce609ac8 (patch) | |
tree | c39b130444b24e1f30b7256fb4f81cae45ed798c | |
parent | 8f071db0da0531f0a311f8544f1f41ff031e0491 (diff) | |
download | nspr-hg-23ce721903fe29d95f36d63bc90b45cdce609ac8.tar.gz |
implement mktime for WinCE
-rw-r--r-- | pr/include/md/_win32_time.h | 14 | ||||
-rw-r--r-- | pr/include/md/_wince.h | 1 | ||||
-rw-r--r-- | pr/src/md/windows/w32time.c | 118 |
3 files changed, 106 insertions, 27 deletions
diff --git a/pr/include/md/_win32_time.h b/pr/include/md/_win32_time.h index f60ca18d..306fc9ac 100644 --- a/pr/include/md/_win32_time.h +++ b/pr/include/md/_win32_time.h @@ -151,6 +151,20 @@ SystemTimeToFileTime(&inSystemTime, &result); \ _MD_FILETIME_2_PRTime(outPRTime, result); \ PR_END_MACRO +#define _MD_SYSTEMTIME_2_time_t(outTimeT, inSystemTime) \ + PR_BEGIN_MACRO \ + FILETIME result; \ + \ + SystemTimeToFileTime(&inSystemTime, &result); \ + _MD_FILETIME_2_time_t(outTimeT, result); \ + PR_END_MACRO +#define _MD_time_t_2_SYSTEMTIME(outSystemTime, inTimeT) \ + PR_BEGIN_MACRO \ + FILETIME conversion; \ + \ + _MD_time_t_2_FILETIME(conversion, inTimeT); \ + FileTimeToSystemTime(&conversion, &outSystemTime); \ + PR_END_MACRO #define _MD_time_t_2_LOCALSYSTEMTIME(outSystemTime, inTimeT) \ PR_BEGIN_MACRO \ FILETIME conversion; \ diff --git a/pr/include/md/_wince.h b/pr/include/md/_wince.h index b9706c24..54b1212a 100644 --- a/pr/include/md/_wince.h +++ b/pr/include/md/_wince.h @@ -551,6 +551,7 @@ struct tm { int tm_yday; int tm_isdst; }; +extern struct tm* Wingmtime(const time_t* inTimeT); extern struct tm* Winlocaltime(const time_t* inTimeT); extern time_t Winmktime(struct tm* inTM); extern size_t Winstrftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr); diff --git a/pr/src/md/windows/w32time.c b/pr/src/md/windows/w32time.c index 0b27ac5a..78233114 100644 --- a/pr/src/md/windows/w32time.c +++ b/pr/src/md/windows/w32time.c @@ -44,9 +44,18 @@ #include "primpl.h" /* - * Winlocaltime + * Ugh, LIBC docs should have warned you. + * A signle static storage for the struct tm's returned by some funcs. + */ +static const int sDaysOfYear[12] = { + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 +}; +static struct tm tmStorage; + +/* + * Winlocaltime * - * As LIBC localtime + * As LIBC localtime */ struct tm* Winlocaltime(const time_t* inTimeT) { @@ -54,14 +63,7 @@ struct tm* Winlocaltime(const time_t* inTimeT) if(NULL != inTimeT) { - static struct tm tmStorage; - static const int daysOfYear[12] = - { - 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 - }; SYSTEMTIME winLocalTime; - TIME_ZONE_INFORMATION winTZInfo; - DWORD winDST; _MD_time_t_2_LOCALSYSTEMTIME(winLocalTime, *inTimeT); @@ -72,8 +74,9 @@ struct tm* Winlocaltime(const time_t* inTimeT) tmStorage.tm_mon = (int)(winLocalTime.wMonth - 1); tmStorage.tm_year = (int)(winLocalTime.wYear - 1900); tmStorage.tm_wday = (int)winLocalTime.wDayOfWeek; - - tmStorage.tm_yday = (int)winLocalTime.wDay + daysOfYear[tmStorage.tm_mon]; + tmStorage.tm_isdst = -1; + + tmStorage.tm_yday = (int)winLocalTime.wDay + sDaysOfYear[tmStorage.tm_mon]; if(0 == (winLocalTime.wYear & 3)) { if(2 < winLocalTime.wMonth) @@ -92,19 +95,53 @@ struct tm* Winlocaltime(const time_t* inTimeT) } } - winDST = GetTimeZoneInformation(&winTZInfo); + retval = &tmStorage; + } + + return retval; +} - switch(winDST) +/* + * Wingmtime + * + * As LIBC gmtime + */ +struct tm* Wingmtime(const time_t* inTimeT) +{ + struct tm* retval = NULL; + + if(NULL != inTimeT) + { + SYSTEMTIME winGMTime; + + _MD_time_t_2_SYSTEMTIME(winGMTime, *inTimeT); + + tmStorage.tm_sec = (int)winGMTime.wSecond; + tmStorage.tm_min = (int)winGMTime.wMinute; + tmStorage.tm_hour = (int)winGMTime.wHour; + tmStorage.tm_mday = (int)winGMTime.wDay; + tmStorage.tm_mon = (int)(winGMTime.wMonth - 1); + tmStorage.tm_year = (int)(winGMTime.wYear - 1900); + tmStorage.tm_wday = (int)winGMTime.wDayOfWeek; + tmStorage.tm_isdst = -1; + + tmStorage.tm_yday = (int)winGMTime.wDay + sDaysOfYear[tmStorage.tm_mon]; + if(0 == (winGMTime.wYear & 3)) { - case TIME_ZONE_ID_STANDARD: - tmStorage.tm_isdst = 0; - break; - case TIME_ZONE_ID_DAYLIGHT: - tmStorage.tm_isdst = 1; - break; - default: - tmStorage.tm_isdst = -1; - break; + if(2 < winGMTime.wMonth) + { + if(0 == winGMTime.wYear % 100) + { + if(0 == winGMTime.wYear % 400) + { + tmStorage.tm_yday++; + } + } + else + { + tmStorage.tm_yday++; + } + } } retval = &tmStorage; @@ -117,16 +154,43 @@ struct tm* Winlocaltime(const time_t* inTimeT) * Winmktime * * As LIBCs mktime + * We likely have a deficiency with the handling of tm_isdst... */ time_t Winmktime(struct tm* inTM) { time_t retval = (time_t)-1; - /* - ** FIXME TODO - ** - ** More here - */ + if(NULL != inTM) + { + SYSTEMTIME winTime; + struct tm* gmTime = NULL; + + memset(&winTime, 0, sizeof(winTime)); + + /* + * Ignore tm_wday and tm_yday. + */ + winTime.wSecond = inTM->tm_sec; + winTime.wMinute = inTM->tm_min; + winTime.wHour = inTM->tm_hour; + winTime.wDay = inTM->tm_mday; + winTime.wMonth = inTM->tm_mon + 1; + winTime.wYear = inTM->tm_year + 1900; + + /* + * First get our time_t. + */ + _MD_SYSTEMTIME_2_time_t(retval, winTime); + + /* + * Now overwrite the struct passed in with what we believe it should be. + */ + gmTime = Wingmtime(&retval); + if(gmTime != inTM) + { + memcpy(inTM, gmTime, sizeof(struct tm)); + } + } return retval; } |