~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Source/NSTimeZone.m

Tags: upstream-1.11.2
ImportĀ upstreamĀ versionĀ 1.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
   You should have received a copy of the GNU Library General Public
23
23
   License along with this library; if not, write to the Free Software
24
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
24
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
25
25
 
26
26
   <title>NSTimeZone class reference</title>
27
 
   $Date: 2005/02/22 11:22:44 $ $Revision: 1.70 $
 
27
   $Date: 2005/11/06 13:53:40 $ $Revision: 1.82 $
28
28
 */
29
29
 
30
30
/* Use the system time zones if available. In other cases, use an
196
196
}
197
197
@end
198
198
 
199
 
#ifdef WIN32
 
199
#if     defined(__WIN32__)
200
200
@interface      GSWindowsTimeZone : NSTimeZone
201
201
{
202
202
@public
395
395
        }
396
396
 
397
397
      if (zone == nil && length > 19
398
 
        && [name hasPrefix: @"NSAbsoluteTimeZone:"] == YES)
 
398
        && [name hasPrefix: @"NSAbsoluteTimeZone: "] == YES)
399
399
        {
400
400
          i = [[name substringFromIndex: 19] intValue];
401
401
 
418
418
                }
419
419
 
420
420
              fileName = [NSTimeZoneClass getTimeZoneFile: name];
421
 
              if (fileName == nil || ![[NSFileManager defaultManager] fileExistsAtPath:fileName])
422
 
#ifdef WIN32
 
421
              if (fileName == nil
 
422
                || ![[NSFileManager defaultManager] fileExistsAtPath: fileName])
 
423
#if     defined(__WIN32__)
423
424
                {
424
 
                  zone = [[GSWindowsTimeZone alloc] initWithName:name data:0];
 
425
                  zone = [[GSWindowsTimeZone alloc] initWithName: name data: 0];
425
426
                  RELEASE(self);
426
427
                  return zone;
427
428
                }
433
434
#endif
434
435
              data = [NSData dataWithContentsOfFile: fileName];
435
436
            }
436
 
#ifdef WIN32
437
 
        if (!data)
438
 
          zone = [[GSWindowsTimeZone alloc] initWithName: name data: data];
439
 
        else
 
437
#if     defined(__WIN32__)
 
438
          if (!data)
 
439
            zone = [[GSWindowsTimeZone alloc] initWithName: name data: data];
 
440
          else
440
441
#endif
441
442
          zone = [[GSTimeZone alloc] initWithName: name data: data];
442
443
        }
674
675
  return offset;
675
676
}
676
677
 
677
 
- (NSTimeZone*) timeZoneDetailTimeZone
 
678
- (NSArray*) timeZoneDetailArray
678
679
{
679
 
  return [NSTimeZone arrayWithObject: detail];
 
680
  return [NSArray arrayWithObject: detail];
680
681
}
681
682
 
682
683
- (NSTimeZoneDetail*) timeZoneDetailForDate: (NSDate*)date
909
910
  /* Read dictionary from file. */
910
911
  abbreviationMap = [[NSMutableDictionary alloc] init];
911
912
  path = _time_zone_path (ABBREV_MAP, nil);
912
 
#if     defined(__WIN32__)
913
 
  file = fopen([path fileSystemRepresentation], "rb");
 
913
#if     defined(__MINGW32__)
 
914
  {
 
915
    unichar     mode[3];
 
916
    mode[0] = 'r';
 
917
    mode[1] = 'b';
 
918
    mode[2] = '\0';
 
919
    file = _wfopen((const unichar*)[path fileSystemRepresentation], mode);
 
920
  }
914
921
#else
915
922
  file = fopen([path fileSystemRepresentation], "r");
916
923
#endif
970
977
 
971
978
  for (i = 0; i < [regionsArray count]; i++)
972
979
    {
973
 
      array = [regionsArray objectAtIndex:i];
 
980
      array = [regionsArray objectAtIndex: i];
974
981
      [temp_array addObjectsFromArray: array];
975
982
    }
976
983
 
1203
1210
          localZoneString = [localZoneString stringByResolvingSymlinksInPath];
1204
1211
#else
1205
1212
          NSFileManager *dflt = [NSFileManager defaultManager];
 
1213
 
1206
1214
          if ([dflt fileExistsAtPath: SYSTEM_TIME_FILE])
1207
1215
            {
1208
1216
              localZoneString = SYSTEM_TIME_FILE;
1209
 
              localZoneString = [localZoneString stringByResolvingSymlinksInPath];
 
1217
              localZoneString
 
1218
                = [localZoneString stringByResolvingSymlinksInPath];
1210
1219
              /* Guess what tzdir is */
1211
1220
              tzdir = [localZoneString stringByDeletingLastPathComponent];
1212
1221
              while ([tzdir length] > 2
1213
 
                     && [dflt fileExistsAtPath: [tzdir stringByAppendingPathComponent: @"GMT"]] == NO)
1214
 
                tzdir = [tzdir stringByDeletingLastPathComponent];
 
1222
                && [dflt fileExistsAtPath:
 
1223
                [tzdir stringByAppendingPathComponent: @"GMT"]] == NO)
 
1224
                {
 
1225
                  tzdir = [tzdir stringByDeletingLastPathComponent];
 
1226
                }
1215
1227
              if ([tzdir length] > 2)
1216
 
                RETAIN(tzdir);
 
1228
                {
 
1229
                  RETAIN(tzdir);
 
1230
                }
1217
1231
              else
1218
1232
                {
1219
1233
                  localZoneString = tzdir = nil;
1223
1237
          if (localZoneString != nil && [localZoneString hasPrefix: tzdir])
1224
1238
            {
1225
1239
              /* This must be the time zone name */
1226
 
              localZoneString = [[localZoneString mutableCopy] autorelease];
 
1240
              localZoneString = AUTORELEASE([localZoneString mutableCopy]);
1227
1241
              [(NSMutableString *)localZoneString deletePrefix: tzdir];
1228
1242
              if ([localZoneString hasPrefix: @"/"])
1229
1243
                {
1231
1245
                }
1232
1246
            }
1233
1247
          else
1234
 
            localZoneString = nil;
 
1248
            {
 
1249
              localZoneString = nil;
 
1250
            }
1235
1251
        }
1236
1252
#if HAVE_TZSET
1237
1253
      /*
1245
1261
        }
1246
1262
#endif
1247
1263
 
1248
 
#ifdef WIN32
 
1264
#if     defined(__WIN32__)
1249
1265
      /*
1250
1266
       * Try to get timezone from windows registry.
1251
1267
       */
1252
1268
      {
1253
1269
        HKEY regkey;
1254
1270
 
1255
 
        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, \
1256
 
        "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", 0, KEY_READ, &regkey))
 
1271
        if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
 
1272
          "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
 
1273
          0,
 
1274
          KEY_READ,
 
1275
          &regkey))
1257
1276
          {
1258
1277
            char buf[255];
1259
1278
            DWORD bufsize=255;
1260
1279
            DWORD type;
1261
 
            if (ERROR_SUCCESS==RegQueryValueEx(regkey, "StandardName", 0, &type, buf, &bufsize))
 
1280
 
 
1281
            if (ERROR_SUCCESS == RegQueryValueExA(regkey,
 
1282
              "StandardName",
 
1283
              0,
 
1284
              &type,
 
1285
              buf,
 
1286
              &bufsize))
1262
1287
              {
1263
 
                bufsize=strlen(buf);
 
1288
                bufsize = strlen(buf);
1264
1289
                while (bufsize && isspace(buf[bufsize-1]))
1265
1290
                  {
1266
1291
                    bufsize--;
1267
1292
                  }
1268
 
                  localZoneString = [NSString stringWithCString:buf length:bufsize];
 
1293
                localZoneString
 
1294
                  = [NSString stringWithCString: buf length: bufsize];
1269
1295
              }
1270
1296
            RegCloseKey(regkey);
1271
1297
          }
1329
1355
    temp_array[i] = [NSMutableArray array];
1330
1356
 
1331
1357
  fileName = _time_zone_path (REGIONS_FILE, nil);
1332
 
#if     defined(__WIN32__)
1333
 
  file = fopen([fileName fileSystemRepresentation], "rb");
 
1358
#if     defined(__MINGW32__)
 
1359
  {
 
1360
    unichar     mode[3];
 
1361
    mode[0] = 'r';
 
1362
    mode[1] = 'b';
 
1363
    mode[2] = '\0';
 
1364
    file = _wfopen((const unichar*)[fileName fileSystemRepresentation], mode);
 
1365
  }
1334
1366
#else
1335
1367
  file = fopen([fileName fileSystemRepresentation], "r");
1336
1368
#endif
1362
1394
}
1363
1395
 
1364
1396
/**
1365
 
 * Returns a timezone for the specified abbrevition. The same abbreviations
 
1397
 * Returns a timezone for the specified abbreviation. The same abbreviations
1366
1398
 * are used in different regions so this isn't particularly useful.<br />
1367
1399
 * Calls NSTimeZone-abbreviation dictionary an so uses a lot of memory.
1368
1400
 */
1569
1601
/**
1570
1602
 * Returns the number of seconds by which the receiver differs
1571
1603
 * from Greenwich Mean Time at the date aDate.<br />
1572
 
 * If the time zone uses dayl;ight savings time, the returned value
 
1604
 * If the time zone uses daylight savings time, the returned value
1573
1605
 * will vary at different times of year.
1574
1606
 */
1575
1607
- (int) secondsFromGMTForDate: (NSDate*)aDate
1675
1707
@end
1676
1708
 
1677
1709
 
1678
 
#ifdef WIN32
 
1710
#if     defined(__WIN32__)
1679
1711
/* Timezone information data as stored in the registry */
1680
1712
typedef struct TZI_format {
1681
1713
        LONG       Bias;
1710
1742
  int *hour, int *minute, int *second, int *mil);
1711
1743
int dayOfCommonEra(NSTimeInterval when);
1712
1744
 
 
1745
 
 
1746
/* FIXME
 
1747
 * It's not unicode ... which is OK as the timezone registry
 
1748
 * names are ascii ... but we ought to be consistent.
 
1749
 */
 
1750
 
1713
1751
@implementation GSWindowsTimeZone
1714
1752
 
1715
1753
- (NSString*) abbreviationForDate: (NSDate*)aDate
1716
1754
{
1717
 
  if ([self isDaylightSavingTimeForDate:aDate])
 
1755
  if ([self isDaylightSavingTimeForDate: aDate])
1718
1756
    return daylightZoneNameAbbr;
1719
1757
  return timeZoneNameAbbr;
1720
1758
}
1721
1759
 
1722
1760
- (NSData*) data
1723
1761
{
1724
 
        return 0;
 
1762
  return 0;
1725
1763
}
1726
1764
 
1727
1765
- (void) dealloc
1735
1773
 
1736
1774
- (id) initWithName: (NSString*)name data: (NSData*)data
1737
1775
{
1738
 
  HKEY     regDirKey;
1739
 
  BOOL     isNT = NO,regFound=NO;
 
1776
  HKEY  regDirKey;
 
1777
  BOOL  isNT = NO;
 
1778
  BOOL  regFound = NO;
1740
1779
 
1741
 
  /* Open the key in the local machine hive where the time zone data is stored. */
1742
 
  if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, &regDirKey))
1743
 
  {
1744
 
    isNT=YES;
1745
 
    regFound=YES;
1746
 
  }
 
1780
  /* Open the key in the local machine hive where
 
1781
   * the time zone data is stored. */
 
1782
  if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
 
1783
    "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
 
1784
    0,
 
1785
    KEY_READ,
 
1786
    &regDirKey))
 
1787
    {
 
1788
      isNT = YES;
 
1789
      regFound = YES;
 
1790
    }
1747
1791
  else
1748
 
  {
1749
 
    if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0, KEY_READ, &regDirKey))
1750
1792
    {
1751
 
        regFound=YES;
 
1793
      if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
 
1794
        "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
 
1795
        0,
 
1796
        KEY_READ,
 
1797
        &regDirKey))
 
1798
        {
 
1799
          regFound = YES;
 
1800
        }
1752
1801
    }
1753
 
  }
1754
1802
 
1755
1803
  if (regFound)
1756
 
  {
1757
 
        /* Iterate over all subKeys in the registry to find the right one.
1758
 
           Unfortunately name is a localized value. The keys in the registry are
1759
 
           unlocalized names. */
1760
 
           CHAR     achKey[255];              // buffer for subkey name
1761
 
        DWORD    cbName;                   // size of name string
1762
 
        CHAR     achClass[MAX_PATH] = "";  // buffer for class name
1763
 
        DWORD    cchClassName = MAX_PATH;  // size of class string
1764
 
        DWORD    cSubKeys=0;               // number of subkeys
1765
 
        DWORD    cbMaxSubKey;              // longest subkey size
1766
 
        DWORD    cchMaxClass;              // longest class string
1767
 
        DWORD    cValues;                  // number of values for key
1768
 
        DWORD    cchMaxValue;              // longest value name
1769
 
        DWORD    cbMaxValueData;           // longest value data
1770
 
        DWORD    cbSecurityDescriptor;     // size of security descriptor
1771
 
        FILETIME ftLastWriteTime;          // last write time
1772
 
                
1773
 
                DWORD i, retCode;
1774
 
                BOOL    tzFound = NO;
1775
 
                
1776
 
                /* Get the class name and the value count. */
1777
 
            retCode = RegQueryInfoKey(
1778
 
                regDirKey,               // key handle
1779
 
                achClass,                // buffer for class name
1780
 
                &cchClassName,           // size of class string
1781
 
                NULL,                    // reserved
1782
 
                &cSubKeys,               // number of subkeys
1783
 
                &cbMaxSubKey,            // longest subkey size
1784
 
                &cchMaxClass,            // longest class string
1785
 
                &cValues,                // number of values for this key
1786
 
                &cchMaxValue,            // longest value name
1787
 
                &cbMaxValueData,         // longest value data
1788
 
                &cbSecurityDescriptor,   // security descriptor
1789
 
                &ftLastWriteTime);       // last write time
1790
 
 
1791
 
        if (cSubKeys && (retCode == ERROR_SUCCESS))
1792
 
        {
1793
 
                const char *cName = [name cString];
1794
 
 
1795
 
                        for (i=0; i<cSubKeys && !tzFound; i++)
1796
 
                        {
1797
 
                           cbName = 255;
1798
 
                        
1799
 
                           retCode = RegEnumKeyEx(regDirKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime);
1800
 
                           if (retCode == ERROR_SUCCESS)
1801
 
                           {
1802
 
                                 char keyBuffer[16384];
1803
 
                                 HKEY regKey;
1804
 
                        
1805
 
                               if (isNT)
1806
 
                                sprintf(keyBuffer,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s",achKey);
1807
 
                                         else
1808
 
                                sprintf(keyBuffer,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones\\%s",achKey);
1809
 
                        
1810
 
                          if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyBuffer, 0, KEY_READ, &regKey))
1811
 
                               {
1812
 
                                      char buf[256];
1813
 
                                      char standardName[256];
1814
 
                                      char daylightName[256];
1815
 
                                      DWORD bufsize;
1816
 
                                      DWORD type;
1817
 
 
1818
 
                                                /* check standardname */
1819
 
                                                standardName[0]='\0';
1820
 
                                      bufsize=sizeof(buf);
1821
 
                                      if (ERROR_SUCCESS==RegQueryValueEx(regKey, "Std", 0, &type, buf, &bufsize))
1822
 
                                      {
1823
 
                                        strcpy(standardName,buf);
1824
 
                                        if (strcmp(standardName,cName) == 0)
1825
 
                                                tzFound = YES;
1826
 
                                        }
1827
 
                
1828
 
                                                /* check daylightname */
1829
 
                                                daylightName[0]='\0';
1830
 
                                      bufsize=sizeof(buf);
1831
 
                                      if (ERROR_SUCCESS==RegQueryValueEx(regKey, "Dlt", 0, &type, buf, &bufsize))
1832
 
                                      {
1833
 
                                        strcpy(daylightName,buf);
1834
 
                                        if (strcmp(daylightName,cName) == 0)
1835
 
                                                tzFound = YES;
1836
 
                                        }
1837
 
 
1838
 
                                                if (tzFound)
1839
 
                                                {
1840
 
                                              /* Read in the time zone data */
1841
 
                                              bufsize=sizeof(buf);
1842
 
                                              if (ERROR_SUCCESS==RegQueryValueEx(regKey, "TZI", 0, &type, buf, &bufsize))
1843
 
                                              {
1844
 
                                                  TZI *tzi = (void*)buf;
1845
 
                                                  Bias = tzi->Bias;
1846
 
                                                  StandardBias = tzi->StandardBias;
1847
 
                                                  DaylightBias = tzi->DaylightBias;
1848
 
                                                  StandardDate = tzi->StandardDate;
1849
 
                                                  DaylightDate = tzi->DaylightDate;
1850
 
                                              }
1851
 
                                        
1852
 
                                              /* Set the standard name for the time zone. */
1853
 
                                              if (strlen(standardName))
1854
 
                                              {
1855
 
                                                  int a, b;
1856
 
                                                  [timeZoneName release];
1857
 
                                                  timeZoneName = [[NSString stringWithCString:standardName] retain];
1858
 
 
1859
 
                                                  /* Abbr generated here is IMHO a bit suspicous but I kept it */
1860
 
                                                  for (a=0,b=0;standardName[a];a++)
1861
 
                                                  {
1862
 
                                                    if (isupper(standardName[a]))
1863
 
                                                      standardName[b++]=standardName[a];
1864
 
                                                  }
1865
 
                                                  standardName[b]=0;
1866
 
                                                  [timeZoneNameAbbr release];
1867
 
                                                  timeZoneNameAbbr = [[NSString stringWithCString:standardName] retain];
1868
 
                                              }
1869
 
 
1870
 
                                              /* Set the daylight savings name for the time zone. */
1871
 
                                              if (strlen(daylightName))
1872
 
                                              {
1873
 
                                                  int a,b;
1874
 
                                                  [daylightZoneName release];
1875
 
                                                  daylightZoneName = [[NSString stringWithCString:daylightName] retain];
1876
 
 
1877
 
                                                  /* Abbr generated here is IMHO a bit suspicous but I kept it */
1878
 
                                                  for (a=0,b=0;daylightName[a];a++)
1879
 
                                                  {
1880
 
                                                      if (isupper(daylightName[a]))
1881
 
                                                        daylightName[b++]=daylightName[a];
1882
 
                                                  }
1883
 
                                                  daylightName[b]=0;
1884
 
                                                  [daylightZoneNameAbbr release];
1885
 
                                                  daylightZoneNameAbbr = [[NSString stringWithCString:daylightName] retain];
1886
 
                                        }
1887
 
                                        }
1888
 
                                      RegCloseKey(regKey);
1889
 
                                }                       
1890
 
                           }
1891
 
                        }
1892
 
        }
 
1804
    {
 
1805
      /* Iterate over all subKeys in the registry to find the right one.
 
1806
         Unfortunately name is a localized value. The keys in the registry are
 
1807
         unlocalized names. */
 
1808
      CHAR     achKey[255];              // buffer for subkey name
 
1809
      DWORD    cbName;                   // size of name string
 
1810
      CHAR     achClass[MAX_PATH] = "";  // buffer for class name
 
1811
      DWORD    cchClassName = MAX_PATH;  // size of class string
 
1812
      DWORD    cSubKeys=0;               // number of subkeys
 
1813
      DWORD    cbMaxSubKey;              // longest subkey size
 
1814
      DWORD    cchMaxClass;              // longest class string
 
1815
      DWORD    cValues;                  // number of values for key
 
1816
      DWORD    cchMaxValue;              // longest value name
 
1817
      DWORD    cbMaxValueData;           // longest value data
 
1818
      DWORD    cbSecurityDescriptor;     // size of security descriptor
 
1819
      FILETIME ftLastWriteTime;          // last write time
 
1820
      DWORD i;
 
1821
      DWORD retCode;
 
1822
      BOOL      tzFound = NO;
 
1823
              
 
1824
              /* Get the class name and the value count. */
 
1825
      retCode = RegQueryInfoKeyA(
 
1826
        regDirKey,               // key handle
 
1827
        achClass,                // buffer for class name
 
1828
        &cchClassName,           // size of class string
 
1829
        NULL,                    // reserved
 
1830
        &cSubKeys,               // number of subkeys
 
1831
        &cbMaxSubKey,            // longest subkey size
 
1832
        &cchMaxClass,            // longest class string
 
1833
        &cValues,                // number of values for this key
 
1834
        &cchMaxValue,            // longest value name
 
1835
        &cbMaxValueData,         // longest value data
 
1836
        &cbSecurityDescriptor,   // security descriptor
 
1837
        &ftLastWriteTime);       // last write time
 
1838
 
 
1839
      if (cSubKeys && (retCode == ERROR_SUCCESS))
 
1840
        {
 
1841
          const char *cName = [name cString];
 
1842
 
 
1843
          for (i = 0; i < cSubKeys && !tzFound; i++)
 
1844
            {
 
1845
              cbName = 255;
 
1846
            
 
1847
              retCode = RegEnumKeyExA(regDirKey,
 
1848
                i,
 
1849
                achKey,
 
1850
                &cbName,
 
1851
                NULL,
 
1852
                NULL,
 
1853
                NULL,
 
1854
                &ftLastWriteTime);
 
1855
              if (retCode == ERROR_SUCCESS)
 
1856
                {
 
1857
                  char keyBuffer[16384];
 
1858
                  HKEY regKey;
 
1859
            
 
1860
                  if (isNT)
 
1861
                    {
 
1862
                      sprintf(keyBuffer, "SOFTWARE\\Microsoft\\Windows NT"
 
1863
                        "\\CurrentVersion\\Time Zones\\%s", achKey);
 
1864
                    }
 
1865
                  else
 
1866
                    {
 
1867
                      sprintf(keyBuffer, "SOFTWARE\\Microsoft\\Windows"
 
1868
                        "\\CurrentVersion\\Time Zones\\%s", achKey);
 
1869
                    }
 
1870
            
 
1871
                  if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
 
1872
                    keyBuffer,
 
1873
                    0,
 
1874
                    KEY_READ,
 
1875
                    &regKey))
 
1876
                    {
 
1877
                      char buf[256];
 
1878
                      char standardName[256];
 
1879
                      char daylightName[256];
 
1880
                      DWORD bufsize;
 
1881
                      DWORD type;
 
1882
 
 
1883
                      /* check standardname */
 
1884
                      standardName[0]='\0';
 
1885
                      bufsize=sizeof(buf);
 
1886
                      if (ERROR_SUCCESS == RegQueryValueExA(regKey,
 
1887
                        "Std",
 
1888
                        0,
 
1889
                        &type,
 
1890
                        buf,
 
1891
                        &bufsize))
 
1892
                        {
 
1893
                          strcpy(standardName, buf);
 
1894
                          if (strcmp(standardName, cName) == 0)
 
1895
                            tzFound = YES;
 
1896
                        }
 
1897
 
 
1898
                      /* check daylightname */
 
1899
                      daylightName[0]='\0';
 
1900
                      bufsize = sizeof(buf);
 
1901
                      if (ERROR_SUCCESS == RegQueryValueExA(regKey,
 
1902
                        "Dlt",
 
1903
                        0,
 
1904
                        &type,
 
1905
                        buf,
 
1906
                        &bufsize))
 
1907
                        {
 
1908
                          strcpy(daylightName, buf);
 
1909
                          if (strcmp(daylightName, cName) == 0)
 
1910
                            tzFound = YES;
 
1911
                        }
 
1912
 
 
1913
                      if (tzFound)
 
1914
                        {
 
1915
                          /* Read in the time zone data */
 
1916
                          bufsize = sizeof(buf);
 
1917
                          if (ERROR_SUCCESS == RegQueryValueExA(regKey,
 
1918
                            "TZI",
 
1919
                            0,
 
1920
                            &type,
 
1921
                            buf,
 
1922
                            &bufsize))
 
1923
                            {
 
1924
                              TZI *tzi = (void*)buf;
 
1925
                              Bias = tzi->Bias;
 
1926
                              StandardBias = tzi->StandardBias;
 
1927
                              DaylightBias = tzi->DaylightBias;
 
1928
                              StandardDate = tzi->StandardDate;
 
1929
                              DaylightDate = tzi->DaylightDate;
 
1930
                            }
 
1931
                    
 
1932
                          /* Set the standard name for the time zone. */
 
1933
                          if (strlen(standardName))
 
1934
                            {
 
1935
                              int a, b;
 
1936
 
 
1937
                              ASSIGN(timeZoneName,
 
1938
                                [NSString stringWithCString: standardName]);
 
1939
 
 
1940
                              /* Abbr generated here is IMHO a
 
1941
                               * bit suspicous but I kept it */
 
1942
                              for (a = 0, b = 0; standardName[a]; a++)
 
1943
                                {
 
1944
                                  if (isupper(standardName[a]))
 
1945
                                    standardName[b++] = standardName[a];
 
1946
                                }
 
1947
                              standardName[b] = 0;
 
1948
                              ASSIGN(timeZoneNameAbbr,
 
1949
                                [NSString stringWithCString: standardName]);
 
1950
                            }
 
1951
 
 
1952
                          /* Set the daylight savings name for the time zone. */
 
1953
                          if (strlen(daylightName))
 
1954
                            {
 
1955
                              int a, b;
 
1956
 
 
1957
                              ASSIGN(daylightZoneName,
 
1958
                                [NSString stringWithCString: daylightName]);
 
1959
 
 
1960
                              /* Abbr generated here is IMHO
 
1961
                               * a bit suspicous but I kept it */
 
1962
                              for (a = 0, b = 0; daylightName[a]; a++)
 
1963
                                {
 
1964
                                  if (isupper(daylightName[a]))
 
1965
                                    daylightName[b++] = daylightName[a];
 
1966
                                }
 
1967
                              daylightName[b] = 0;
 
1968
                              ASSIGN(daylightZoneNameAbbr,
 
1969
                                [NSString stringWithCString: daylightName]);
 
1970
                            }
 
1971
                        }
 
1972
                      RegCloseKey(regKey);
 
1973
                    }                   
 
1974
                }
 
1975
            }
 
1976
        }
1893
1977
      RegCloseKey(regDirKey);
1894
 
  }
1895
 
 
 
1978
    }
1896
1979
  return self;
1897
1980
}
1898
1981
 
2000
2083
 
2001
2084
- (int) secondsFromGMTForDate: (NSDate*)aDate
2002
2085
{
2003
 
  if ([self isDaylightSavingTimeForDate:aDate])
 
2086
  if ([self isDaylightSavingTimeForDate: aDate])
2004
2087
    return -Bias*60 - DaylightBias*60;
2005
2088
  return -Bias*60 - StandardBias*60;
2006
2089
}
2007
2090
 
2008
2091
- (NSArray*) timeZoneDetailArray
2009
2092
{
2010
 
        return [NSArray arrayWithObjects:
2011
 
                 [[[GSTimeZoneDetail alloc] initWithTimeZone:self
2012
 
                            withAbbrev:timeZoneNameAbbr
2013
 
                            withOffset:-Bias*60 - StandardBias*60
2014
 
                            withDST:NO] autorelease],
2015
 
                 [[[GSTimeZoneDetail alloc] initWithTimeZone:self
2016
 
                            withAbbrev:daylightZoneNameAbbr
2017
 
                            withOffset:-Bias*60 - DaylightBias*60
2018
 
                            withDST:YES] autorelease], 0];
 
2093
  return [NSArray arrayWithObjects:
 
2094
    [[[GSTimeZoneDetail alloc] initWithTimeZone: self
 
2095
      withAbbrev: timeZoneNameAbbr
 
2096
      withOffset: -Bias*60 - StandardBias*60
 
2097
      withDST: NO] autorelease],
 
2098
    [[[GSTimeZoneDetail alloc] initWithTimeZone: self
 
2099
      withAbbrev: daylightZoneNameAbbr
 
2100
      withOffset: -Bias*60 - DaylightBias*60
 
2101
      withDST: YES] autorelease], 0];
2019
2102
}
2020
2103
 
2021
2104
- (NSTimeZoneDetail*) timeZoneDetailForDate: (NSDate*)aDate
2022
2105
{
2023
2106
  GSTimeZoneDetail      *detail;
2024
2107
  int offset;
2025
 
  BOOL isDST = [self isDaylightSavingTimeForDate:aDate];
 
2108
  BOOL isDST = [self isDaylightSavingTimeForDate: aDate];
2026
2109
  NSString *abbr;
2027
2110
 
2028
2111
  if (isDST)
2048
2131
  return timeZoneName;
2049
2132
}
2050
2133
@end
2051
 
#endif // WIN32
 
2134
#endif // __WIN32__
2052
2135
 
2053
2136
 
2054
2137
@implementation GSTimeZone
2250
2333
          types[i].offset = decode(ptr->offset);
2251
2334
          pos += sizeof(struct ttinfo);
2252
2335
        }
2253
 
      abbr = (char*)(bytes + pos);
 
2336
      abbr = (unsigned char*)(bytes + pos);
2254
2337
      {
2255
2338
        id      abbrevs[charcnt];
2256
2339
 
2261
2344
 
2262
2345
            if (abbrevs[loc] == nil)
2263
2346
              {
2264
 
                abbrevs[loc] = [[NSString alloc] initWithCString: abbr + loc];
 
2347
                abbrevs[loc]
 
2348
                  = [[NSString alloc] initWithCString: (char*)abbr + loc];
2265
2349
              }
2266
2350
            else
2267
2351
              {