Improvement for GetTimeZoneInformation

Vincent Béron vberon at mecano.gme.usherb.ca
Mon May 27 22:12:07 CDT 2002


I need some help to finish this implementation. I don't have access to
an english version of Windows NT4 or 2K or XP, so I couldn't finish the
array of the timezones. COuld somebody help me a bit on this one? I'm
planning on actually writing the equivalence in Unix timezones, so you
only need to give me the names of the Windows timezones. I have a small
program to help you if you need it.

Changelog:
 - Improves the implementation of GetTimeZoneInformation. Missing some
Windows timezone names.

Vincent
-------------- next part --------------
diff -urN wine-orig/dlls/kernel/time.c wine-pas-compil?/dlls/kernel/time.c
--- wine-orig/dlls/kernel/time.c	Wed May 15 22:28:45 2002
+++ wine-pas-compil?/dlls/kernel/time.c	Mon May 27 22:00:34 2002
@@ -43,14 +43,39 @@
 */
 struct tagTZ_INFO
 {
-    const char *psTZFromUnix;
-    WCHAR psTZWindows[32];
-    int bias;
-    int dst;
+    const char *psTZFromUnixStandard;
+    const char *psTZFromUnixDaylight;
+    TIME_ZONE_INFORMATION tzi;
 };
 
 static const struct tagTZ_INFO TZ_INFO[] =
 {
+   {"PST", "PDT",
+    {480,
+     {'P', 'a', 'c', 'i', 'f', 'i', 'c', '\0'},
+     {0, 10, 0, 5, 2, 0, 0, 0}, 0,
+     {'P', 'a', 'c', 'i', 'f', 'i', 'c', ' ', '(', 'd', 'a', 'y', 'l', 'i', 'g', 'h', 't', ')', '\0'},
+     {0, 4, 0, 1, 2, 0, 0, 0}, -60}},
+   {"MST", "MDT",
+    {420,
+     {'M', 'o', 'u', 'n', 't', 'a', 'i', 'n', '\0'},
+     {0, 10, 0, 5, 2, 0, 0, 0}, 0,
+     {'M', 'o', 'u', 'n', 't', 'a', 'i', 'n', ' ', '(', 'd', 'a', 'y', 'l', 'i', 'g', 'h', 't', ')', '\0'},
+     {0, 4, 0, 1, 2, 0, 0, 0}, -60}},
+   {"CST", "CDT",
+    {360,
+     {'C', 'e', 'n', 't', 'r', 'a', 'l', '\0'},
+     {0, 10, 0, 5, 2, 0, 0, 0}, 0,
+     {'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', '(', 'd', 'a', 'y', 'l', 'i', 'g', 'h', 't', ')', '\0'},
+     {0, 4, 0, 1, 2, 0, 0, 0}, -60}},
+   {"EST", "EDT",
+    {300,
+     {'E', 'a', 's', 't', 'e', 'r', 'n', '\0'},
+     {0, 10, 0, 5, 2, 0, 0, 0}, 0,
+     {'E', 'a', 's', 't', 'e', 'r', 'n', ' ', '(', 'd', 'a', 'y', 'l', 'i', 'g', 'h', 't', ')', '\0'},
+     {0, 4, 0, 1, 2, 0, 0, 0}, -60}}
+};
+/*{
    {"MHT", 
     {'D','a','t','e','l','i','n','e',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
     -720, 0},
@@ -243,28 +268,26 @@
    {"TOT",
     {'T','o','n','g','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
     -780, 0}
-};
+};*/
 
-/* TIME_GetTZAsStr: helper function that returns the given timezone as a string.
-   This could be done with a hash table instead of merely iterating through
-   a table, however with the small amount of entries (60 or so) I didn't think
-   it was worth it. */
-static const WCHAR* TIME_GetTZAsStr (time_t utc, int bias, int dst)
+/* TIME_GetTZAsTZINFO: helper function that returns the given timezone as a
+   pointer to a TIME_ZONE_INFORMATION structure. This could be done with a
+   hash table instead of merely iterating through a table, however with the
+   small amount of entries (60 or so) I didn't think it was worth it. */
+static const TIME_ZONE_INFORMATION* TIME_GetTZAsTZINFO (time_t utc, int *pdaylight)
 {
    char psTZName[7];
    struct tm *ptm = localtime(&utc);
    int i;
 
+   *pdaylight = -1;
    if (!strftime (psTZName, 7, "%Z", ptm))
       return (NULL);
-
-   for (i=0; i<(sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++) 
-   {
-      if ( strcmp(TZ_INFO[i].psTZFromUnix, psTZName) == 0 &&
-           TZ_INFO[i].bias == bias &&
-           TZ_INFO[i].dst == dst
-         )
-            return TZ_INFO[i].psTZWindows;
+   *pdaylight = ptm->tm_isdst;
+   for (i = 0; i < (sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++) {
+      if ( strcmp(TZ_INFO[i].psTZFromUnixStandard, psTZName) == 0 ||
+           strcmp(TZ_INFO[i].psTZFromUnixDaylight, psTZName) == 0)
+            return &(TZ_INFO[i].tzi);
    }
 
    return (NULL);
@@ -447,21 +469,32 @@
     LPTIME_ZONE_INFORMATION tzinfo) /* [out] The time zone structure to be filled in. */
 {
     time_t gmt;
-    int bias, daylight;
-    const WCHAR *psTZ;
-
+    const TIME_ZONE_INFORMATION *ptTZI;
+    int daylight;
 
     memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
 
     gmt = time(NULL);
-    bias=TIME_GetBias(gmt,&daylight);
-
-    tzinfo->Bias = -bias / 60;
-    tzinfo->StandardBias = 0;
-    tzinfo->DaylightBias = -60;
-    psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight);
-    if (psTZ) strcpyW( tzinfo->StandardName, psTZ );
-    return TIME_ZONE_ID_STANDARD;
+    ptTZI = TIME_GetTZAsTZINFO (gmt, &daylight);
+    if(ptTZI) {
+	tzinfo->Bias = ptTZI->Bias;
+	strcpyW(tzinfo->StandardName, ptTZI->StandardName);
+	memcpy(&(tzinfo->StandardDate), &(ptTZI->StandardDate), sizeof(SYSTEMTIME));
+	tzinfo->StandardBias = ptTZI->StandardBias;
+	strcpyW(tzinfo->DaylightName, ptTZI->DaylightName);
+	memcpy(&(tzinfo->DaylightDate), &(ptTZI->DaylightDate), sizeof(SYSTEMTIME));
+	tzinfo->DaylightBias = ptTZI->DaylightBias;
+	if(daylight == 0) {
+	    return TIME_ZONE_ID_STANDARD;
+	} else if(daylight > 0) {
+	    return TIME_ZONE_ID_DAYLIGHT;
+	} else {
+	    return TIME_ZONE_ID_UNKNOWN;
+	}
+    } else {
+	SetLastError(ERROR_UNKNOWN);
+	return TIME_ZONE_ID_INVALID;
+    }
 }
 
 


More information about the wine-patches mailing list