Skip to content

Commit a61b058

Browse files
spevansparkera
authored andcommitted
SR-8078: Some time zone identifiers are not supported by TimeZone on Linux (#1616)
- TimeZone.knownTimeZoneIdentifiers was returning time zone names that could not be instantiated by TimeZone(identifier:) due to CFTimeZone.c:__nameStringOK() filtering out some names. - Make CFTimeZoneCopyKnownNames(), used by .knownTimeZoneIdentifiers, also filter these names using __nameStringOK(). - __nameStringOK calls ICU function ucal_getCanonicalTimeZoneID which ultimately decides if the time zone is valid.
1 parent eff149c commit a61b058

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ void CFTimeZoneSetDefault(CFTimeZoneRef tz) {
891891
}
892892

893893
static CFDictionaryRef __CFTimeZoneCopyCompatibilityDictionary(void);
894+
static Boolean __nameStringOK(CFStringRef name);
894895

895896
CFArrayRef CFTimeZoneCopyKnownNames(void) {
896897
CFArrayRef tzs;
@@ -906,7 +907,7 @@ CFArrayRef CFTimeZoneCopyKnownNames(void) {
906907
CFIndex idx;
907908
for (idx = CFArrayGetCount(list); idx--; ) {
908909
CFStringRef item = (CFStringRef)CFArrayGetValueAtIndex(list, idx);
909-
if (CFDictionaryContainsKey(dict, item)) {
910+
if (CFDictionaryContainsKey(dict, item) || !__nameStringOK(item)) {
910911
CFArrayRemoveValueAtIndex(list, idx);
911912
}
912913
}

TestFoundation/TestTimeZone.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class TestTimeZone: XCTestCase {
2828
// ("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime),
2929

3030
("test_customMirror", test_tz_customMirror),
31+
("test_knownTimeZones", test_knownTimeZones),
3132
]
3233
}
3334

@@ -189,4 +190,12 @@ class TestTimeZone: XCTestCase {
189190
XCTAssertNotNil(children["secondsFromGMT"])
190191
XCTAssertNotNil(children["isDaylightSavingTime"])
191192
}
193+
194+
func test_knownTimeZones() {
195+
let timeZones = TimeZone.knownTimeZoneIdentifiers.sorted()
196+
XCTAssertTrue(timeZones.count > 0, "No known timezones")
197+
for tz in timeZones {
198+
XCTAssertNotNil(TimeZone(identifier: tz), "Cant instantiate valid timeZone: \(tz)")
199+
}
200+
}
192201
}

0 commit comments

Comments
 (0)