Skip to content

Commit 7242fa9

Browse files
authored
localizedName_103036605() fails when the current date is around DST change (#1562)
* localizedName_103036605() fails when the current date is around DST change We saw a test failure in this CI job: https://ci.swift.org/job/oss-swift-6.2-bootstrap-ubuntu-24_04-x86_64/318 ``` [2025-10-26T00:58:39.054Z] ✘ Test localizedName_103036605() recorded an issue at TimeZoneTests.swift:74:13: Expectation failed: (tz?.localizedName(for: .generic, locale: locale) → "Central European Time (Germany)") == (expected → "Central European Time") ``` The cause of this test failure is that this `TimeZone` API uses the current time as reference, and depending on `style` it may include the time zone city to disambiguate that from the [golden zone](https://www.unicode.org/reports/tr35/tr35-dates.html#Using_Time_Zone_Names) if the current time is close to a DST transition. Update the test to use the golden zone to opt out of this unexpected behavior since that is not what this test was meant to test. Also while we're here, update the test to respect the `style` argument. * Add another expectation for when observing DST * Use a fairly stable timezone for test The time zone offset for Vostok recently went through a change. Udpate the test to use a stable time zone for this test
1 parent a8cdd87 commit 7242fa9

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

Tests/FoundationInternationalizationTests/TimeZoneTests.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,41 @@ private struct TimeZoneTests {
5959
}
6060

6161
@Test func localizedName_103036605() {
62-
func test(_ tzIdentifier: String, _ localeIdentifier: String, _ style: TimeZone.NameStyle, _ expected: String?, sourceLocation: SourceLocation = #_sourceLocation) {
62+
func test(_ tzIdentifier: String, _ localeIdentifier: String, _ style: TimeZone.NameStyle, _ expected: String?, _ expectedDST: String?, sourceLocation: SourceLocation = #_sourceLocation) {
6363
let tz = TimeZone(identifier: tzIdentifier)
6464
guard let expected else {
6565
#expect(tz == nil, sourceLocation: sourceLocation)
6666
return
6767
}
6868

6969
let locale = Locale(identifier: localeIdentifier)
70-
#expect(tz?.localizedName(for: .generic, locale: locale) == expected, sourceLocation: sourceLocation)
70+
if let tz, tz.isDaylightSavingTime(for: .now) {
71+
#expect(tz.localizedName(for: style, locale: locale) == expectedDST, sourceLocation: sourceLocation)
72+
} else {
73+
#expect(tz?.localizedName(for: style, locale: locale) == expected, sourceLocation: sourceLocation)
74+
}
7175
}
7276

73-
test("America/Los_Angeles", "en_US", .generic, "Pacific Time")
74-
test("Europe/Berlin", "en_US", .generic, "Central European Time")
75-
test("Antarctica/Vostok", "en_US", .generic, "Vostok Time")
76-
test("Asia/Chongqing", "en_US", .generic, "China Standard Time")
77-
test("America/Sao_Paulo", "en_US", .generic, "Brasilia Standard Time")
77+
test("America/Los_Angeles", "en_US", .generic, "Pacific Time", "Pacific Time")
78+
test("Europe/Paris", "en_US", .generic, "Central European Time", "Central European Time")
79+
test("Antarctica/Vostok", "en_US", .generic, "Vostok Time", "Vostok Time")
80+
test("Asia/Chongqing", "en_US", .generic, "China Standard Time", "China Standard Time")
81+
test("America/Sao_Paulo", "en_US", .generic, "Brasilia Standard Time", "Brasilia Standard Time")
7882

79-
test("America/Los_Angeles", "zh_TW", .shortStandard, "太平洋時間")
80-
test("Europe/Berlin", "zh_TW", .shortStandard, "中歐時間")
81-
test("Antarctica/Vostok", "zh_TW", .shortStandard, "沃斯托克時間")
82-
test("Asia/Chongqing", "zh_TW", .shortStandard, "中國標準時間")
83-
test("America/Sao_Paulo", "zh_TW", .shortStandard, "巴西利亞標準時間")
83+
test("America/Los_Angeles", "zh_TW", .shortStandard, "PST", "PST")
84+
test("Europe/Paris", "zh_TW", .shortStandard, "GMT+1", "GMT+2")
85+
test("Antarctica/Davis", "zh_TW", .shortStandard, "GMT+7", "GMT+7")
86+
test("Asia/Chongqing", "zh_TW", .shortStandard, "GMT+8", "GMT+8")
87+
test("America/Sao_Paulo", "zh_TW", .shortStandard, "GMT-3", "GMT-3")
8488

8589
// abbreviation
86-
test("GMT", "en_US", .standard, "Greenwich Mean Time")
87-
test("GMT+8", "en_US", .standard, "GMT+08:00")
88-
test("PST", "en_US", .standard, "Pacific Time")
90+
test("GMT", "en_US", .standard, "Greenwich Mean Time", "Greenwich Mean Time")
91+
test("GMT+8", "en_US", .standard, "GMT+08:00", "GMT+08:00")
92+
test("PST", "en_US", .standard, "Pacific Standard Time", "Pacific Standard Time")
8993

9094
// invalid names
91-
test("XYZ", "en_US", .standard, nil)
92-
test("BOGUS/BOGUS", "en_US", .standard, nil)
95+
test("XYZ", "en_US", .standard, nil, nil)
96+
test("BOGUS/BOGUS", "en_US", .standard, nil, nil)
9397
}
9498

9599
@Test func timeZoneName_103097012() throws {

0 commit comments

Comments
 (0)