7
7
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8
8
//
9
9
10
- import CoreFoundation
11
10
12
11
class TestTimeZone : XCTestCase {
13
12
@@ -228,7 +227,39 @@ class TestTimeZone: XCTestCase {
228
227
}
229
228
}
230
229
}
231
-
230
+
231
+ func test_nextDaylightSavingTimeTransition( ) throws {
232
+ // Timezones without DST
233
+ let gmt = try TimeZone ( secondsFromGMT: 0 ) . unwrapped ( )
234
+ let msk = try TimeZone ( identifier: " Europe/Moscow " ) . unwrapped ( )
235
+
236
+ // Timezones with DST
237
+ let bst = try TimeZone ( abbreviation: " BST " ) . unwrapped ( )
238
+ let aest = try TimeZone ( identifier: " Australia/Sydney " ) . unwrapped ( )
239
+
240
+ XCTAssertNil ( gmt. nextDaylightSavingTimeTransition)
241
+ XCTAssertNil ( msk. nextDaylightSavingTimeTransition)
242
+ XCTAssertNotNil ( bst. nextDaylightSavingTimeTransition)
243
+ XCTAssertNotNil ( aest. nextDaylightSavingTimeTransition)
244
+
245
+ let formatter = DateFormatter ( )
246
+ formatter. timeZone = TimeZone ( identifier: " UTC " )
247
+ formatter. dateFormat = " yyyy-MM-dd "
248
+
249
+ let dt1 = try formatter. date ( from: " 2018-01-01 " ) . unwrapped ( )
250
+ XCTAssertNil ( gmt. nextDaylightSavingTimeTransition ( after: dt1) )
251
+ XCTAssertNil ( msk. nextDaylightSavingTimeTransition ( after: dt1) )
252
+ XCTAssertEqual ( bst. nextDaylightSavingTimeTransition ( after: dt1) ? . description, " 2018-03-25 01:00:00 +0000 " )
253
+ XCTAssertEqual ( aest. nextDaylightSavingTimeTransition ( after: dt1) ? . description, " 2018-03-31 16:00:00 +0000 " )
254
+
255
+ formatter. timeZone = aest
256
+ let dt2 = try formatter. date ( from: " 2018-06-06 " ) . unwrapped ( )
257
+ XCTAssertNil ( gmt. nextDaylightSavingTimeTransition ( after: dt2) )
258
+ XCTAssertNil ( msk. nextDaylightSavingTimeTransition ( after: dt2) )
259
+ XCTAssertEqual ( bst. nextDaylightSavingTimeTransition ( after: dt2) ? . description, " 2018-10-28 01:00:00 +0000 " )
260
+ XCTAssertEqual ( aest. nextDaylightSavingTimeTransition ( after: dt2) ? . description, " 2018-10-06 16:00:00 +0000 " )
261
+ }
262
+
232
263
static var allTests : [ ( String , ( TestTimeZone ) -> ( ) throws -> Void ) ] {
233
264
var tests : [ ( String , ( TestTimeZone ) -> ( ) throws -> Void ) ] = [
234
265
( " test_abbreviation " , test_abbreviation) ,
@@ -247,6 +278,7 @@ class TestTimeZone: XCTestCase {
247
278
( " test_knownTimeZones " , test_knownTimeZones) ,
248
279
( " test_systemTimeZoneName " , test_systemTimeZoneName) ,
249
280
( " test_autoupdatingTimeZone " , test_autoupdatingTimeZone) ,
281
+ ( " test_nextDaylightSavingTimeTransition " , test_nextDaylightSavingTimeTransition) ,
250
282
]
251
283
252
284
#if !os(Windows)
0 commit comments