@@ -138,6 +138,63 @@ private struct TimeZoneTests {
138138 try testAbbreviation ( " UTC+0900 " , 32400 , " GMT+0900 " )
139139 }
140140
141+ @Test func timeZoneGMTOffset( ) throws {
142+ func testName( _ name: String , _ expectedOffset: Int , sourceLocation: SourceLocation = #_sourceLocation) throws {
143+ let tz = try #require( TimeZone ( identifier: name) )
144+ let secondsFromGMT = tz. secondsFromGMT ( )
145+ #expect( secondsFromGMT == expectedOffset)
146+ #expect( tz. isDaylightSavingTime ( ) == false )
147+ #expect( tz. nextDaylightSavingTimeTransition == nil )
148+ }
149+
150+ try testName ( " GMT+8 " , 8 * 3600 )
151+ try testName ( " GMT+08 " , 8 * 3600 )
152+ try testName ( " GMT+0800 " , 8 * 3600 )
153+ try testName ( " GMT+08:00 " , 8 * 3600 )
154+ try testName ( " GMT+8:00 " , 8 * 3600 )
155+ try testName ( " UTC+9 " , 9 * 3600 )
156+ try testName ( " UTC+09 " , 9 * 3600 )
157+ try testName ( " UTC+0900 " , 9 * 3600 )
158+ try testName ( " UTC+09:00 " , 9 * 3600 )
159+ try testName ( " UTC+9:00 " , 9 * 3600 )
160+ }
161+
162+ @Test( arguments: [ " en_001 " , " en_US " , " ja_JP " ] )
163+ func timeZoneGMTOffset_localizedNames( localeIdentifier: String) throws {
164+ let locale = Locale ( identifier: localeIdentifier)
165+ func testNames(
166+ _ names: [ String ] ,
167+ _ expectedStandardName: String ,
168+ _ expectedShortStandardName: String ,
169+ _ expectedDaylightSavingName: String ,
170+ _ expectedShortDaylightSavingName: String ,
171+ _ expectedGenericName: String ,
172+ _ expectedShortGenericName: String ,
173+ sourceLocation: SourceLocation = #_sourceLocation) throws {
174+ for name in names {
175+ let tz = try #require( TimeZone ( identifier: name) )
176+ let standardName = tz. localizedName ( for: . standard, locale: locale)
177+ let shortStandardName = tz. localizedName ( for: . shortStandard, locale: locale)
178+ let daylightSavingName = tz. localizedName ( for: . daylightSaving, locale: locale)
179+ let shortDaylightSavingName = tz. localizedName ( for: . shortDaylightSaving, locale: locale)
180+ let generic = tz. localizedName ( for: . generic, locale: locale)
181+ let shortGeneric = tz. localizedName ( for: . shortGeneric, locale: locale)
182+
183+ #expect( expectedStandardName == standardName)
184+ #expect( expectedShortStandardName == shortStandardName)
185+ #expect( expectedDaylightSavingName == daylightSavingName)
186+ #expect( expectedShortDaylightSavingName == shortDaylightSavingName)
187+ #expect( expectedGenericName == generic)
188+ #expect( expectedShortGenericName == shortGeneric)
189+ }
190+ }
191+
192+ try testNames ( [ " GMT+8 " , " GMT+08 " , " GMT+0800 " , " GMT+08:00 " , " GMT+8:00 " ] ,
193+ " GMT+08:00 " , " GMT+8 " , " GMT+08:00 " , " GMT+8 " , " GMT+08:00 " , " GMT+8 " )
194+ try testNames ( [ " UTC+9 " , " UTC+09 " , " UTC+0900 " , " UTC+09:00 " , " UTC+9:00 " ] ,
195+ " GMT+09:00 " , " GMT+9 " , " GMT+09:00 " , " GMT+9 " , " GMT+09:00 " , " GMT+9 " )
196+ }
197+
141198 @Test func secondsFromGMT_RemoteDates( ) {
142199 let date = Date ( timeIntervalSinceReferenceDate: - 5001243627 ) // "1842-07-09T05:39:33+0000"
143200 let europeRome = TimeZone ( identifier: " Europe/Rome " ) !
0 commit comments