Skip to content

Commit 9e32385

Browse files
committed
TimeZone: delegate to ICU on Windows
Unfortunately, Windows does not have full time zone information available. For many cases we can make do with the system information, augmented with alternate names (the Olson-to-Windows conversion database). This papers over the inability to deserialize the full information in the registry by falling back to ICU to get the information for the DST time conversion.
1 parent f80087a commit 9e32385

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,18 +1679,34 @@ CFTimeInterval CFTimeZoneGetDaylightSavingTimeOffset(CFTimeZoneRef tz, CFAbsolut
16791679
return 0.0;
16801680
}
16811681

1682+
extern UCalendar *__CFCalendarCreateUCalendar(CFStringRef calendarID, CFStringRef localeID, CFTimeZoneRef tz);
1683+
16821684
CFAbsoluteTime CFTimeZoneGetNextDaylightSavingTimeTransition(CFTimeZoneRef tz, CFAbsoluteTime at) {
16831685
CF_OBJC_FUNCDISPATCHV(CFTimeZoneGetTypeID(), CFTimeInterval, (NSTimeZone *)tz, _nextDaylightSavingTimeTransitionAfterAbsoluteTime:at);
16841686
__CFGenericValidateType(tz, CFTimeZoneGetTypeID());
1687+
#if TARGET_OS_WIN32
1688+
UErrorCode status = U_ZERO_ERROR;
1689+
UCalendar *ucal = __CFCalendarCreateUCalendar(NULL, CFSTR("C"), tz);
1690+
if (ucal == NULL) {
1691+
return 0.0;
1692+
}
1693+
ucal_setMillis(ucal, (at + kCFAbsoluteTimeIntervalSince1970) * 1000.0, &status);
1694+
1695+
UDate date;
1696+
ucal_getTimeZoneTransitionDate(ucal, UCAL_TZ_TRANSITION_NEXT, &date, &status);
1697+
1698+
ucal_close(ucal);
1699+
1700+
return (date / 1000.0) - kCFAbsoluteTimeIntervalSince1970;
1701+
#else
16851702
CFIndex idx = __CFBSearchTZPeriods(tz, at);
16861703
if (tz->_periodCnt <= idx + 1) {
16871704
return 0.0;
16881705
}
16891706
return (CFAbsoluteTime)__CFTZPeriodStartSeconds(&(tz->_periods[idx + 1]));
1707+
#endif
16901708
}
16911709

1692-
extern UCalendar *__CFCalendarCreateUCalendar(CFStringRef calendarID, CFStringRef localeID, CFTimeZoneRef tz);
1693-
16941710
#define BUFFER_SIZE 768
16951711

16961712
CFStringRef CFTimeZoneCopyLocalizedName(CFTimeZoneRef tz, CFTimeZoneNameStyle style, CFLocaleRef locale) {

0 commit comments

Comments
 (0)