Timezone fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@5664 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-01-05 14:53:03 +00:00
parent 1a92814749
commit 98f56b39be
2 changed files with 65 additions and 32 deletions

View file

@ -1,3 +1,16 @@
Wed Jan 5 14:37:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSTimeZone.m: Changed order of lookup to determine the local
timezone:
1. User defaults with key 'Local Time Zone'
2. GNUSTEP_TZ environment variable
3. $GNUSTEP_SYSTEM_ROOT/Libraries/Resources/NSTimeZones/localtime
4. TZ environment variable
5. Use UTC
This means that the TZ environment variable can now safely be used for
non-GNUstep timezones as long as GNUSTEP_TZ is defined (or a localtime)
file exists.
Wed Jan 5 10:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Wed Jan 5 10:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSTimeZones/NSTimeZones.tar: Made a revised set of timezones with * NSTimeZones/NSTimeZones.tar: Made a revised set of timezones with

View file

@ -33,9 +33,9 @@
2038 problem.) 2038 problem.)
The local time zone can be specified with the user defaults The local time zone can be specified with the user defaults
database, the TZ environment variable, the file LOCAL_TIME_FILE, or database, the GNUSTEP_TZ environment variable, the file LOCAL_TIME_FILE,
the fallback time zone (which is UTC), with the ones listed first the TZ environment variable, or the fallback time zone (which is UTC),
having precedence. with the ones listed first having precedence.
Any time zone must be a file name in ZONES_DIR. Any time zone must be a file name in ZONES_DIR.
@ -571,41 +571,61 @@ static NSMapTable *absolutes = 0;
zoneDictionary = [[NSMutableDictionary alloc] init]; zoneDictionary = [[NSMutableDictionary alloc] init];
localZoneString = [[NSUserDefaults standardUserDefaults] localZoneString = [[NSUserDefaults standardUserDefaults]
stringForKey: LOCALDBKEY]; stringForKey: LOCALDBKEY];
if (localZoneString == nil) if (localZoneString == nil)
/* Try to get timezone from environment. */ {
localZoneString = [[[NSProcessInfo processInfo] /*
environment] objectForKey: @"TZ"]; * Try to get timezone from GNUSTEP_TZ environment variable.
*/
localZoneString = [[[NSProcessInfo processInfo]
environment] objectForKey: @"GNUSTEP_TZ"];
}
if (localZoneString == nil) if (localZoneString == nil)
/* Try to get timezone from LOCAL_TIME_FILE. */ {
{ /*
NSString *f = [NSTimeZone getLocalTimeFile]; * Try to get timezone from LOCAL_TIME_FILE.
char zone_name[80]; */
FILE *fp; NSString *f = [NSTimeZone getLocalTimeFile];
char zone_name[80];
FILE *fp;
if (f) if (f != 0)
{ {
#if defined(__WIN32__) #if defined(__WIN32__)
fp = fopen([f fileSystemRepresentation], "rb"); fp = fopen([f fileSystemRepresentation], "rb");
#else #else
fp = fopen([f fileSystemRepresentation], "r"); fp = fopen([f fileSystemRepresentation], "r");
#endif #endif
if (fp != NULL) if (fp != NULL)
{ {
if (fscanf(fp, "%79s", zone_name) == 1) if (fscanf(fp, "%79s", zone_name) == 1)
localZoneString = [NSString stringWithCString: zone_name]; localZoneString = [NSString stringWithCString: zone_name];
fclose(fp); fclose(fp);
} }
} }
} }
if (localZoneString == nil)
{
/*
* Try to get timezone from standard unix environment variable.
*/
localZoneString = [[[NSProcessInfo processInfo]
environment] objectForKey: @"TZ"];
}
if (localZoneString != nil) if (localZoneString != nil)
localTimeZone = [NSTimeZone timeZoneWithName: localZoneString]; {
localTimeZone = [NSTimeZone timeZoneWithName: localZoneString];
}
else else
NSLog(@"No local time zone specified."); {
NSLog(@"No local time zone specified.");
}
/* If local time zone fails to allocate, then allocate something /*
that is sure to succeed (unless we run out of memory, of * If local time zone fails to allocate, then allocate something
course). */ * that is sure to succeed (unless we run out of memory, of
* course).
*/
if (localTimeZone == nil) if (localTimeZone == nil)
{ {
NSLog(@"Using time zone with absolute offset 0."); NSLog(@"Using time zone with absolute offset 0.");