windows timezone fixup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24547 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-02-14 11:38:52 +00:00
parent 1fd5c43a7c
commit 901e578015
2 changed files with 61 additions and 38 deletions

View file

@ -1,3 +1,7 @@
2007-02-14 Roland Schwingel <roland.schwingel@onevision.de>
* Source/NSTimeZone.m: windows bugfix for daylight savings time.
2007-02-13 Richard Frith-Macdonald <rfm@gnu.org> 2007-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: Don't treat leading '~' in path component or * Source/NSString.m: Don't treat leading '~' in path component or
@ -1093,7 +1097,7 @@
2006-09-10 Richard Frith-Macdonald <rfm@gnu.org> 2006-09-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSTimeZone.m: Remove unnecessary check on fiel name as * Source/NSTimeZone.m: Remove unnecessary check on file name as
Roland Schwingel reported that it caught legitimate files on windows. Roland Schwingel reported that it caught legitimate files on windows.
* Source/NSMessagePort.m: * Source/NSMessagePort.m:
* Source/NSSocketPort.m: * Source/NSSocketPort.m:

View file

@ -1460,36 +1460,21 @@ static NSMapTable *absolutes = 0;
#if defined(__MINGW32__) #if defined(__MINGW32__)
/* /*
* Try to get timezone from windows registry. * Try to get timezone from windows system call.
*/ */
{ {
HKEY regkey; TIME_ZONE_INFORMATION tz;
DWORD DST = GetTimeZoneInformation(&tz);
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE, if (DST == TIME_ZONE_ID_DAYLIGHT)
"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
0,
KEY_READ,
&regkey))
{ {
char buf[255]; localZoneString = [NSString stringWithCharacters: tz.DaylightName
DWORD bufsize=255; length: wcslen(tz.DaylightName)];
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]; else
} {
RegCloseKey(regkey); localZoneString = [NSString stringWithCharacters: tz.StandardName
length: wcslen(tz.StandardName)];
} }
} }
#endif #endif
@ -2353,12 +2338,36 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
GSBreakTime(when, &year, &month, &day, &hour, &minute, &second, &mil); GSBreakTime(when, &year, &month, &day, &hour, &minute, &second, &mil);
// Check north globe
if (StandardDate.wMonth >= DaylightDate.wMonth)
{
// Before April or after October is Std // Before April or after October is Std
if (month < DaylightDate.wMonth || month > StandardDate.wMonth) if (month < DaylightDate.wMonth || month > StandardDate.wMonth)
{
return NO; return NO;
}
// After April and before October is DST // After April and before October is DST
if (month > DaylightDate.wMonth && month < StandardDate.wMonth) if (month > DaylightDate.wMonth && month < StandardDate.wMonth)
{
return YES; 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; dow = ((int)((when / 86400.0) + GREGORIAN_REFERENCE)) % 7;
if (dow < 0) if (dow < 0)
dow += 7; dow += 7;
@ -2436,7 +2445,17 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
- (NSString*) name - (NSString*) name
{ {
TIME_ZONE_INFORMATION tz;
DWORD DST = GetTimeZoneInformation(&tz);
if (DST == TIME_ZONE_ID_DAYLIGHT)
{
return daylightZoneName;
}
else
{
return timeZoneName; return timeZoneName;
}
} }
- (int) secondsFromGMTForDate: (NSDate*)aDate - (int) secondsFromGMTForDate: (NSDate*)aDate
@ -2486,7 +2505,7 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
- (NSString*) timeZoneName - (NSString*) timeZoneName
{ {
return timeZoneName; return [self name];
} }
@end @end
#endif // __MINGW32__ #endif // __MINGW32__