Skip to content

Commit e2951d6

Browse files
committed
fixup
1 parent d84b837 commit e2951d6

File tree

2 files changed

+4
-72
lines changed

2 files changed

+4
-72
lines changed

Sources/AWSLambdaEvents/Utils/DateWrappers.swift

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,14 @@ public struct ISO8601Coding: Decodable {
4848
if #available(macOS 10.12, *) {
4949
return Self.dateFormatter.date(from: string)
5050
} else {
51-
return self.decodeISO8601Date(from: string).flatMap(Date.init(timeIntervalSince1970:))
51+
// unlikely *debugging* use case of swift 5.2+ on older macOS
52+
preconditionFailure("Unsporrted macOS version")
5253
}
5354
#endif
5455
}
5556

5657
@available(macOS 10.12, *)
5758
private static let dateFormatter = ISO8601DateFormatter()
58-
59-
// strptime not avail on through Glibc
60-
#if os(macOS)
61-
// 1970-01-01T00:00:00Z
62-
internal static func decodeISO8601Date(from string: String) -> Double? {
63-
if string.last != "Z" {
64-
return nil
65-
}
66-
var parsedTime = tm()
67-
_ = string.withCString { cstr in
68-
strptime(cstr, "%Y-%m-%dT%H:%M:%S", &parsedTime)
69-
}
70-
let time = timegm(&parsedTime)
71-
if time == -1 {
72-
return nil
73-
}
74-
return Double(time)
75-
}
76-
#endif
7759
}
7860

7961
@propertyWrapper
@@ -101,7 +83,8 @@ public struct ISO8601WithFractionalSecondsCoding: Decodable {
10183
if #available(macOS 10.13, *) {
10284
return self.dateFormatter.date(from: string)
10385
} else {
104-
return self.decodeISO8601Date(from: string).flatMap(Date.init(timeIntervalSince1970:))
86+
// unlikely *debugging* use case of swift 5.2+ on older macOS
87+
preconditionFailure("Unsporrted macOS version")
10588
}
10689
#endif
10790
}
@@ -121,28 +104,6 @@ public struct ISO8601WithFractionalSecondsCoding: Decodable {
121104
]
122105
return formatter
123106
}
124-
125-
// strptime not avail on through Glibc
126-
#if os(macOS)
127-
// 1970-01-01T00:00:00.00Z
128-
internal static func decodeISO8601Date(from string: String) -> Double? {
129-
guard let msIndex = string.lastIndex(of: ".") else {
130-
return nil
131-
}
132-
guard let endIndex = string.lastIndex(of: "Z") else {
133-
return nil
134-
}
135-
if endIndex <= msIndex {
136-
return nil
137-
}
138-
let msString = string[msIndex ..< endIndex]
139-
guard let ms = Double(msString) else {
140-
return nil
141-
}
142-
143-
return ISO8601Coding.decodeISO8601Date(from: string)?.advanced(by: ms)
144-
}
145-
#endif
146107
}
147108

148109
@propertyWrapper

Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ class DateWrapperTests: XCTestCase {
4848
}
4949
}
5050

51-
#if os(macOS)
52-
@available(macOS 10.12, *)
53-
func testISO8601CustomDecoder() {
54-
let formatter = ISO8601DateFormatter()
55-
let string = formatter.string(from: Date())
56-
let date = formatter.date(from: string)
57-
let date2 = ISO8601Coding.decodeISO8601Date(from: string)
58-
XCTAssertEqual(date?.timeIntervalSince1970, date2)
59-
}
60-
#endif
61-
6251
func testISO8601WithFractionalSecondsCodingWrapperSuccess() {
6352
struct TestEvent: Decodable {
6453
@ISO8601WithFractionalSecondsCoding
@@ -91,24 +80,6 @@ class DateWrapperTests: XCTestCase {
9180
}
9281
}
9382

94-
#if os(macOS)
95-
@available(macOS 10.13, *)
96-
func testISO8601WithFractionalSecondsCustomDecoder() {
97-
let formatter = ISO8601DateFormatter()
98-
formatter.formatOptions = [
99-
.withInternetDateTime,
100-
.withDashSeparatorInDate,
101-
.withColonSeparatorInTime,
102-
.withColonSeparatorInTimeZone,
103-
.withFractionalSeconds,
104-
]
105-
let string = formatter.string(from: Date())
106-
let date = formatter.date(from: string)
107-
let date2 = ISO8601WithFractionalSecondsCoding.decodeISO8601Date(from: string)
108-
XCTAssertEqual(date?.timeIntervalSince1970, date2)
109-
}
110-
#endif
111-
11283
func testRFC5322DateTimeCodingWrapperSuccess() {
11384
struct TestEvent: Decodable {
11485
@RFC5322DateTimeCoding

0 commit comments

Comments
 (0)