Skip to content

Commit d982301

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 d982301

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 10 additions & 2 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
}

0 commit comments

Comments
 (0)