@@ -29,6 +29,7 @@ class TestDateFormatter: XCTestCase {
2929 ( " test_dateFrom " , test_dateFrom) ,
3030 ( " test_dateParseAndFormatWithJapaneseCalendar " , test_dateParseAndFormatWithJapaneseCalendar) ,
3131 ( " test_orderOfPropertySetters " , test_orderOfPropertySetters) ,
32+ ( " test_copy_sr14108 " , test_copy_sr14108) ,
3233 ]
3334 }
3435
@@ -527,4 +528,29 @@ class TestDateFormatter: XCTestCase {
527528 }
528529 }
529530 }
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+ }
530556}
0 commit comments