bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bugfix for Windows Timezone Handling


From: Roland Schwingel
Subject: Bugfix for Windows Timezone Handling
Date: Wed, 14 Feb 2007 10:08:04 +0100
User-agent: Thunderbird 1.5.0.9 (Windows/20061207)

Hi...

Recently I stumbled across some problems in Windows timezone handling...
On the southglobe eg. in Australia... Summertime (DST) is "activated" when
we switch to Standardtime and vice versa. The informations for this are present in the windows registry but were not correctly processed. I fixed this. Additionally I fixed the problem of not returning the correct timezone name when DST is enabled
(on all parts of the globe).

I am at present running an older version of GNUstep so I merged the fix to the current
SVN state of NSTimeZone.m.

I hope you can integrate it... Notify me if there are any problems with the patch...

Roland

--- NSTimeZone.m        2007-02-13 19:14:59.000000000 +0100
+++ NSTimeZone.new.m    2007-02-13 22:35:24.000000000 +0100
@@ -1460,37 +1460,15 @@
 
 #if    defined(__MINGW32__)
       /*
-       * Try to get timezone from windows registry.
+       * Try to get timezone from windows system call.
        */
       {
-        HKEY regkey;
-
-        if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
-         "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
-         0,
-         KEY_READ,
-         &regkey))
-          {
-            char buf[255];
-            DWORD bufsize=255;
-            DWORD type;
-
-            if (ERROR_SUCCESS == RegQueryValueExA(regkey,
-             "StandardName",
-             0,
-             &type,
-             buf,
-             &bufsize))
-              {
-                bufsize = strlen(buf);
-                while (bufsize && isspace(buf[bufsize-1]))
-                  {
-                    bufsize--;
-                  }
-               localZoneString = [NSString stringWithUTF8String: buf];
-              }
-            RegCloseKey(regkey);
-          }
+       TIME_ZONE_INFORMATION tz;
+       DWORD DST = GetTimeZoneInformation(&tz);
+       if (DST == TIME_ZONE_ID_DAYLIGHT)
+               localZoneString = [NSString 
stringWithCharacters:tz.DaylightName length:wcslen(tz.DaylightName)];
+       else
+               localZoneString = [NSString 
stringWithCharacters:tz.StandardName length:wcslen(tz.StandardName)];
       }
 #endif
 
@@ -2353,12 +2331,27 @@
 
   GSBreakTime(when, &year, &month, &day, &hour, &minute, &second, &mil);
 
-  // Before April or after October is Std
-  if (month < DaylightDate.wMonth || month > StandardDate.wMonth)
-    return NO;
-  // After April and before October is DST
-  if (month > DaylightDate.wMonth && month < StandardDate.wMonth)
-    return YES;
+  // Check north globe
+  if (StandardDate.wMonth >= DaylightDate.wMonth)
+  {
+         // Before April or after October is Std
+         if (month < DaylightDate.wMonth || month > StandardDate.wMonth)
+                       return NO;
+         // After April and before October is DST
+         if (month > DaylightDate.wMonth && month < StandardDate.wMonth)
+                       return YES;
+  }
+  else
+  {
+               // check south globe 
+       // Before April or after October is DST
+       if (month < StandardDate.wMonth || month > DaylightDate.wMonth)
+               return YES;
+       // After April and before October is Std
+       if (month > StandardDate.wMonth && month < DaylightDate.wMonth)
+               return NO;
+  }
+
   dow = ((int)((when / 86400.0) + GREGORIAN_REFERENCE)) % 7;
   if (dow < 0)
     dow += 7;
@@ -2436,7 +2429,12 @@
 
 - (NSString*) name
 {
-  return timeZoneName;
+       TIME_ZONE_INFORMATION tz;
+       DWORD DST = GetTimeZoneInformation(&tz);
+       if (DST == TIME_ZONE_ID_DAYLIGHT)
+               return daylightZoneName;
+       else
+               return timeZoneName;
 }
 
 - (int) secondsFromGMTForDate: (NSDate*)aDate
@@ -2486,7 +2484,7 @@
 
 - (NSString*) timeZoneName
 {
-  return timeZoneName;
+  return [self name];
 }
 @end
 #endif // __MINGW32__

reply via email to

[Prev in Thread] Current Thread [Next in Thread]