@@ -20,8 +20,8 @@ class TestISO8601DateFormatter: XCTestCase {
20
20
21
21
func test_stringFromDate( ) {
22
22
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 "
25
25
26
26
guard let someDateTime = formatter. date ( from: dateString) else {
27
27
XCTFail ( " DateFormatter was unable to parse ' \( dateString) ' using ' \( formatter. dateFormat ?? " " ) ' date format. " )
@@ -44,6 +44,9 @@ class TestISO8601DateFormatter: XCTestCase {
44
44
isoFormatter. formatOptions = . withFullTime
45
45
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 22:31:00Z " )
46
46
47
+ isoFormatter. formatOptions = [ . withFullTime, . withFractionalSeconds]
48
+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 22:31:00.071Z " )
49
+
47
50
isoFormatter. formatOptions = . withFullDate
48
51
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 2016-10-08 " )
49
52
@@ -53,9 +56,15 @@ class TestISO8601DateFormatter: XCTestCase {
53
56
isoFormatter. formatOptions = [ . withFullTime, . withFullDate, . withSpaceBetweenDateAndTime]
54
57
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 2016-10-08 22:31:00Z " )
55
58
59
+ isoFormatter. formatOptions = [ . withFullTime, . withFullDate, . withSpaceBetweenDateAndTime, . withFractionalSeconds]
60
+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 2016-10-08 22:31:00.071Z " )
61
+
56
62
isoFormatter. formatOptions = [ . withDay, . withTime]
57
63
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 282T223100 " )
58
64
65
+ isoFormatter. formatOptions = [ . withDay, . withTime, . withFractionalSeconds]
66
+ XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 282T223100.071 " )
67
+
59
68
isoFormatter. formatOptions = [ . withWeekOfYear, . withTime]
60
69
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " W40T223100 " )
61
70
@@ -79,6 +88,9 @@ class TestISO8601DateFormatter: XCTestCase {
79
88
80
89
isoFormatter. formatOptions = [ . withWeekOfYear, . withMonth, . withTime, . withColonSeparatorInTime, . withSpaceBetweenDateAndTime, . withDashSeparatorInDate]
81
90
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 " )
82
94
83
95
isoFormatter. formatOptions = [ . withDay, . withWeekOfYear]
84
96
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " W4006 " )
@@ -92,6 +104,10 @@ class TestISO8601DateFormatter: XCTestCase {
92
104
isoFormatter. formatOptions = [ . withDay, . withWeekOfYear, . withMonth]
93
105
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10W4006 " )
94
106
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
+
95
111
isoFormatter. formatOptions = [ . withMonth, . withDay, . withWeekOfYear, . withDashSeparatorInDate]
96
112
XCTAssertEqual ( isoFormatter. string ( from: someDateTime) , " 10-W40-06 " )
97
113
0 commit comments