From 7242fa9cb8993aaf9a0a72522206b96a45da9c28 Mon Sep 17 00:00:00 2001 From: Tina L <49205802+itingliu@users.noreply.github.com> Date: Fri, 31 Oct 2025 09:51:18 -0700 Subject: [PATCH] localizedName_103036605() fails when the current date is around DST change (#1562) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../TimeZoneTests.swift | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/Tests/FoundationInternationalizationTests/TimeZoneTests.swift b/Tests/FoundationInternationalizationTests/TimeZoneTests.swift index 724b15799..daec2d656 100644 --- a/Tests/FoundationInternationalizationTests/TimeZoneTests.swift +++ b/Tests/FoundationInternationalizationTests/TimeZoneTests.swift @@ -59,7 +59,7 @@ private struct TimeZoneTests { } @Test func localizedName_103036605() { - func test(_ tzIdentifier: String, _ localeIdentifier: String, _ style: TimeZone.NameStyle, _ expected: String?, sourceLocation: SourceLocation = #_sourceLocation) { + func test(_ tzIdentifier: String, _ localeIdentifier: String, _ style: TimeZone.NameStyle, _ expected: String?, _ expectedDST: String?, sourceLocation: SourceLocation = #_sourceLocation) { let tz = TimeZone(identifier: tzIdentifier) guard let expected else { #expect(tz == nil, sourceLocation: sourceLocation) @@ -67,29 +67,33 @@ private struct TimeZoneTests { } let locale = Locale(identifier: localeIdentifier) - #expect(tz?.localizedName(for: .generic, locale: locale) == expected, sourceLocation: sourceLocation) + if let tz, tz.isDaylightSavingTime(for: .now) { + #expect(tz.localizedName(for: style, locale: locale) == expectedDST, sourceLocation: sourceLocation) + } else { + #expect(tz?.localizedName(for: style, locale: locale) == expected, sourceLocation: sourceLocation) + } } - test("America/Los_Angeles", "en_US", .generic, "Pacific Time") - test("Europe/Berlin", "en_US", .generic, "Central European Time") - test("Antarctica/Vostok", "en_US", .generic, "Vostok Time") - test("Asia/Chongqing", "en_US", .generic, "China Standard Time") - test("America/Sao_Paulo", "en_US", .generic, "Brasilia Standard Time") + test("America/Los_Angeles", "en_US", .generic, "Pacific Time", "Pacific Time") + test("Europe/Paris", "en_US", .generic, "Central European Time", "Central European Time") + test("Antarctica/Vostok", "en_US", .generic, "Vostok Time", "Vostok Time") + test("Asia/Chongqing", "en_US", .generic, "China Standard Time", "China Standard Time") + test("America/Sao_Paulo", "en_US", .generic, "Brasilia Standard Time", "Brasilia Standard Time") - test("America/Los_Angeles", "zh_TW", .shortStandard, "太平洋時間") - test("Europe/Berlin", "zh_TW", .shortStandard, "中歐時間") - test("Antarctica/Vostok", "zh_TW", .shortStandard, "沃斯托克時間") - test("Asia/Chongqing", "zh_TW", .shortStandard, "中國標準時間") - test("America/Sao_Paulo", "zh_TW", .shortStandard, "巴西利亞標準時間") + test("America/Los_Angeles", "zh_TW", .shortStandard, "PST", "PST") + test("Europe/Paris", "zh_TW", .shortStandard, "GMT+1", "GMT+2") + test("Antarctica/Davis", "zh_TW", .shortStandard, "GMT+7", "GMT+7") + test("Asia/Chongqing", "zh_TW", .shortStandard, "GMT+8", "GMT+8") + test("America/Sao_Paulo", "zh_TW", .shortStandard, "GMT-3", "GMT-3") // abbreviation - test("GMT", "en_US", .standard, "Greenwich Mean Time") - test("GMT+8", "en_US", .standard, "GMT+08:00") - test("PST", "en_US", .standard, "Pacific Time") + test("GMT", "en_US", .standard, "Greenwich Mean Time", "Greenwich Mean Time") + test("GMT+8", "en_US", .standard, "GMT+08:00", "GMT+08:00") + test("PST", "en_US", .standard, "Pacific Standard Time", "Pacific Standard Time") // invalid names - test("XYZ", "en_US", .standard, nil) - test("BOGUS/BOGUS", "en_US", .standard, nil) + test("XYZ", "en_US", .standard, nil, nil) + test("BOGUS/BOGUS", "en_US", .standard, nil, nil) } @Test func timeZoneName_103097012() throws {