@@ -29,6 +29,7 @@ class TestDateFormatter: XCTestCase {
29
29
( " test_dateFrom " , test_dateFrom) ,
30
30
( " test_dateParseAndFormatWithJapaneseCalendar " , test_dateParseAndFormatWithJapaneseCalendar) ,
31
31
( " test_orderOfPropertySetters " , test_orderOfPropertySetters) ,
32
+ ( " test_copy_sr14108 " , test_copy_sr14108) ,
32
33
]
33
34
}
34
35
@@ -527,4 +528,29 @@ class TestDateFormatter: XCTestCase {
527
528
}
528
529
}
529
530
}
531
+
532
+ // Confirm that https://bugs.swift.org/browse/SR-14108 is fixed.
533
+ func test_copy_sr14108( ) throws {
534
+ let date = Date ( timeIntervalSinceReferenceDate: 0 )
535
+
536
+ let original = DateFormatter ( )
537
+ original. timeZone = TimeZone ( identifier: DEFAULT_TIMEZONE)
538
+ original. locale = Locale ( identifier: DEFAULT_LOCALE)
539
+ original. dateFormat = " yyyy-MM-dd HH:mm:ss z "
540
+ XCTAssertEqual ( original. string ( from: date) , " 2001-01-01 00:00:00 GMT " )
541
+
542
+ let copied = try XCTUnwrap ( original. copy ( ) as? DateFormatter )
543
+ XCTAssertEqual ( original. timeZone, copied. timeZone)
544
+ XCTAssertEqual ( original. locale, copied. locale)
545
+ XCTAssertEqual ( copied. string ( from: date) , " 2001-01-01 00:00:00 GMT " )
546
+
547
+ copied. timeZone = TimeZone ( abbreviation: " JST " )
548
+ copied. locale = Locale ( identifier: " ja_JP " )
549
+ copied. dateFormat = " yyyy/MM/dd hh:mm:ssxxxxx "
550
+
551
+ XCTAssertNotEqual ( original. timeZone, copied. timeZone)
552
+ XCTAssertNotEqual ( original. locale, copied. locale)
553
+ XCTAssertEqual ( original. string ( from: date) , " 2001-01-01 00:00:00 GMT " )
554
+ XCTAssertEqual ( copied. string ( from: date) , " 2001/01/01 09:00:00+09:00 " )
555
+ }
530
556
}
0 commit comments