Skip to content

Commit 0dc0dac

Browse files
authored
Merge pull request #612 from saiHemak/nstimezone-branch
Tests for TimeZone.localizedName
2 parents f39a6ba + 8e435a0 commit 0dc0dac

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

TestFoundation/TestNSTimeZone.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TestNSTimeZone: XCTestCase {
3535
("test_computedPropertiesMatchMethodReturnValues", test_computedPropertiesMatchMethodReturnValues),
3636
("test_initializingTimeZoneWithOffset", test_initializingTimeZoneWithOffset),
3737
("test_initializingTimeZoneWithAbbreviation", test_initializingTimeZoneWithAbbreviation),
38-
38+
("test_localizedName", test_localizedName),
3939
// Also disabled due to https://bugs.swift.org/browse/SR-300
4040
// ("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime),
4141
]
@@ -117,6 +117,20 @@ class TestNSTimeZone: XCTestCase {
117117
let known = NSTimeZone.knownTimeZoneNames
118118
XCTAssertNotEqual([], known, "known time zone names not expected to be empty")
119119
}
120+
121+
func test_localizedName() {
122+
let initialTimeZone = NSTimeZone.default
123+
NSTimeZone.default = TimeZone(identifier: "America/New_York")!
124+
let defaultTimeZone = NSTimeZone.default
125+
let locale = Locale(identifier: "en_US")
126+
XCTAssertEqual(defaultTimeZone.localizedName(for: .standard, locale: locale), "Eastern Standard Time")
127+
XCTAssertEqual(defaultTimeZone.localizedName(for: .shortStandard, locale: locale), "EST")
128+
XCTAssertEqual(defaultTimeZone.localizedName(for: .generic, locale: locale), "Eastern Time")
129+
XCTAssertEqual(defaultTimeZone.localizedName(for: .daylightSaving, locale: locale), "Eastern Daylight Time")
130+
XCTAssertEqual(defaultTimeZone.localizedName(for: .shortDaylightSaving, locale: locale), "EDT")
131+
XCTAssertEqual(defaultTimeZone.localizedName(for: .shortGeneric, locale: locale), "ET")
132+
NSTimeZone.default = initialTimeZone //reset the TimeZone
133+
}
120134

121135
func test_initializingTimeZoneWithOffset() {
122136
let tz = TimeZone(identifier: "GMT-0400")

0 commit comments

Comments
 (0)