Skip to content

Commit dadf095

Browse files
committed
[CoreFoundation] Use a Windows Timezone if we are given one
Before attempting to check if a timezone is an abbreviation or Olson format, we should make sure we can't just query Windows for the timezone. For example, CFTimeZoneCopyKnownNames will return UTC[-+XX] timezones which we would otherwise would fail on.
1 parent fff2489 commit dadf095

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,15 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
13071307
Boolean result = false;
13081308

13091309
#if TARGET_OS_WIN32
1310+
// Start by checking if we're just given a timezone Windows knows about
1311+
int32_t offset;
1312+
__CFTimeZoneGetOffset(name, &offset);
1313+
if (offset) {
1314+
// TODO: handle DST
1315+
__CFTimeZoneInitFixed(timeZone, offset, name, 0);
1316+
return TRUE;
1317+
}
1318+
13101319
CFDictionaryRef abbrevs = CFTimeZoneCopyAbbreviationDictionary();
13111320

13121321
tzName = CFDictionaryGetValue(abbrevs, name);
@@ -1319,9 +1328,8 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
13191328
CFRelease(abbrevs);
13201329

13211330
if (tzName) {
1322-
int32_t offset;
13231331
__CFTimeZoneGetOffset(tzName, &offset);
1324-
// TODO(compnerd) handle DST
1332+
// TODO: handle DST
13251333
__CFTimeZoneInitFixed(timeZone, offset, name, 0);
13261334
return TRUE;
13271335
}
@@ -1516,6 +1524,14 @@ CFTimeZoneRef CFTimeZoneCreateWithName(CFAllocatorRef allocator, CFStringRef nam
15161524
CFURLRef baseURL = NULL;
15171525

15181526
#if TARGET_OS_WIN32
1527+
// Start by checking if we're just given a timezone Windows knows about
1528+
int32_t offset;
1529+
__CFTimeZoneGetOffset(name, &offset);
1530+
if (offset) {
1531+
// TODO: handle DST
1532+
result = __CFTimeZoneCreateFixed(allocator, offset, name, 0);
1533+
}
1534+
15191535
CFDictionaryRef abbrevs = CFTimeZoneCopyAbbreviationDictionary();
15201536

15211537
tzName = CFDictionaryGetValue(abbrevs, name);
@@ -1528,9 +1544,8 @@ CFTimeZoneRef CFTimeZoneCreateWithName(CFAllocatorRef allocator, CFStringRef nam
15281544
CFRelease(abbrevs);
15291545

15301546
if (tzName) {
1531-
int32_t offset;
15321547
__CFTimeZoneGetOffset(tzName, &offset);
1533-
// TODO(compnerd) handle DST
1548+
// TODO: handle DST
15341549
result = __CFTimeZoneCreateFixed(allocator, offset, name, 0);
15351550
}
15361551

0 commit comments

Comments
 (0)