@@ -20,8 +20,8 @@ class TestISO8601DateFormatter: XCTestCase {
2020
2121 func test_stringFromDate( ) {
2222 let formatter = DateFormatter ( )
23- formatter. dateFormat = " yyyy/MM/dd HH:mm zzz "
24- let dateString = " 2016/10/08 22:31 GMT "
23+ formatter. dateFormat = " yyyy/MM/dd HH:mm:ss.SSSS zzz "
24+ let dateString = " 2016/10/08 22:31:00.0713 GMT "
2525
2626 guard let someDateTime = formatter. date ( from: dateString) else {
2727 XCTFail ( " DateFormatter was unable to parse ' \( dateString) ' using ' \( formatter. dateFormat ?? " " ) ' date format. " )
@@ -44,6 +44,9 @@ class TestISO8601DateFormatter: XCTestCase {
4444 isoFormatter. formatOptions = . withFullTime
4545 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 22:31:00Z " )
4646
47+ isoFormatter. formatOptions = [ . withFullTime, . withFractionalSeconds]
48+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 22:31:00.071Z " )
49+
4750 isoFormatter. formatOptions = . withFullDate
4851 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 2016-10-08 " )
4952
@@ -53,9 +56,15 @@ class TestISO8601DateFormatter: XCTestCase {
5356 isoFormatter. formatOptions = [ . withFullTime, . withFullDate, . withSpaceBetweenDateAndTime]
5457 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 2016-10-08 22:31:00Z " )
5558
59+ isoFormatter. formatOptions = [ . withFullTime, . withFullDate, . withSpaceBetweenDateAndTime, . withFractionalSeconds]
60+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 2016-10-08 22:31:00.071Z " )
61+
5662 isoFormatter. formatOptions = [ . withDay, . withTime]
5763 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 282T223100 " )
5864
65+ isoFormatter. formatOptions = [ . withDay, . withTime, . withFractionalSeconds]
66+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 282T223100.071 " )
67+
5968 isoFormatter. formatOptions = [ . withWeekOfYear, . withTime]
6069 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " W40T223100 " )
6170
@@ -79,6 +88,9 @@ class TestISO8601DateFormatter: XCTestCase {
7988
8089 isoFormatter. formatOptions = [ . withWeekOfYear, . withMonth, . withTime, . withColonSeparatorInTime, . withSpaceBetweenDateAndTime, . withDashSeparatorInDate]
8190 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10-W40 22:31:00 " )
91+
92+ isoFormatter. formatOptions = [ . withWeekOfYear, . withMonth, . withTime, . withColonSeparatorInTime, . withSpaceBetweenDateAndTime, . withDashSeparatorInDate, . withFractionalSeconds]
93+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10-W40 22:31:00.071 " )
8294
8395 isoFormatter. formatOptions = [ . withDay, . withWeekOfYear]
8496 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " W4006 " )
@@ -92,6 +104,10 @@ class TestISO8601DateFormatter: XCTestCase {
92104 isoFormatter. formatOptions = [ . withDay, . withWeekOfYear, . withMonth]
93105 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10W4006 " )
94106
107+ // .withFractionalSeconds should be ignored if neither .withTime or .withFullTime are specified
108+ isoFormatter. formatOptions = [ . withDay, . withWeekOfYear, . withMonth, . withFractionalSeconds]
109+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10W4006 " )
110+
95111 isoFormatter. formatOptions = [ . withMonth, . withDay, . withWeekOfYear, . withDashSeparatorInDate]
96112 XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10-W40-06 " )
97113
0 commit comments