Skip to content

Commit f731664

Browse files
authored
remove requirment on macOS 10.13 (#156)
motivation: simplify downstream libraries changes: precondition out debugging uses cases on macOS < 10.13
1 parent f3c68d6 commit f731664

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

Package.swift

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import PackageDescription
44

55
let package = Package(
66
name: "swift-aws-lambda-runtime",
7-
platforms: [
8-
.macOS(.v10_13),
9-
],
107
products: [
118
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
129
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),

Sources/AWSLambdaEvents/Utils/DateWrappers.swift

+35-5
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,27 @@ public struct ISO8601Coding: Decodable {
2828
public init(from decoder: Decoder) throws {
2929
let container = try decoder.singleValueContainer()
3030
let dateString = try container.decode(String.self)
31-
guard let date = Self.dateFormatter.date(from: dateString) else {
31+
guard let date = Self.decodeDate(from: dateString) else {
3232
throw DecodingError.dataCorruptedError(in: container, debugDescription:
33-
"Expected date to be in iso8601 date format, but `\(dateString)` does not forfill format")
33+
"Expected date to be in ISO8601 date format, but `\(dateString)` is not in the correct format")
3434
}
3535
self.wrappedValue = date
3636
}
3737

38+
private static func decodeDate(from string: String) -> Date? {
39+
#if os(Linux)
40+
return Self.dateFormatter.date(from: string)
41+
#elseif os(macOS)
42+
if #available(macOS 10.12, *) {
43+
return Self.dateFormatter.date(from: string)
44+
} else {
45+
// unlikely *debugging* use case of swift 5.2+ on older macOS
46+
preconditionFailure("Unsporrted macOS version")
47+
}
48+
#endif
49+
}
50+
51+
@available(macOS 10.12, *)
3852
private static let dateFormatter = ISO8601DateFormatter()
3953
}
4054

@@ -49,14 +63,30 @@ public struct ISO8601WithFractionalSecondsCoding: Decodable {
4963
public init(from decoder: Decoder) throws {
5064
let container = try decoder.singleValueContainer()
5165
let dateString = try container.decode(String.self)
52-
guard let date = Self.dateFormatter.date(from: dateString) else {
66+
guard let date = Self.decodeDate(from: dateString) else {
5367
throw DecodingError.dataCorruptedError(in: container, debugDescription:
54-
"Expected date to be in iso8601 date format with fractional seconds, but `\(dateString)` does not forfill format")
68+
"Expected date to be in ISO8601 date format with fractional seconds, but `\(dateString)` is not in the correct format")
5569
}
5670
self.wrappedValue = date
5771
}
5872

73+
private static func decodeDate(from string: String) -> Date? {
74+
#if os(Linux)
75+
return Self.dateFormatter.date(from: string)
76+
#elseif os(macOS)
77+
if #available(macOS 10.13, *) {
78+
return self.dateFormatter.date(from: string)
79+
} else {
80+
// unlikely *debugging* use case of swift 5.2+ on older macOS
81+
preconditionFailure("Unsporrted macOS version")
82+
}
83+
#endif
84+
}
85+
86+
@available(macOS 10.13, *)
5987
private static let dateFormatter: ISO8601DateFormatter = Self.createDateFormatter()
88+
89+
@available(macOS 10.13, *)
6090
private static func createDateFormatter() -> ISO8601DateFormatter {
6191
let formatter = ISO8601DateFormatter()
6292
formatter.formatOptions = [
@@ -88,7 +118,7 @@ public struct RFC5322DateTimeCoding: Decodable {
88118
}
89119
guard let date = Self.dateFormatter.date(from: string) else {
90120
throw DecodingError.dataCorruptedError(in: container, debugDescription:
91-
"Expected date to be in RFC5322 date-time format with fractional seconds, but `\(string)` does not forfill format")
121+
"Expected date to be in RFC5322 date-time format with fractional seconds, but `\(string)` is not in the correct format")
92122
}
93123
self.wrappedValue = date
94124
}

Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DateWrapperTests: XCTestCase {
4343
}
4444

4545
XCTAssertEqual(context.codingPath.compactMap { $0.stringValue }, ["date"])
46-
XCTAssertEqual(context.debugDescription, "Expected date to be in iso8601 date format, but `\(date)` does not forfill format")
46+
XCTAssertEqual(context.debugDescription, "Expected date to be in ISO8601 date format, but `\(date)` is not in the correct format")
4747
XCTAssertNil(context.underlyingError)
4848
}
4949
}
@@ -75,7 +75,7 @@ class DateWrapperTests: XCTestCase {
7575
}
7676

7777
XCTAssertEqual(context.codingPath.compactMap { $0.stringValue }, ["date"])
78-
XCTAssertEqual(context.debugDescription, "Expected date to be in iso8601 date format with fractional seconds, but `\(date)` does not forfill format")
78+
XCTAssertEqual(context.debugDescription, "Expected date to be in ISO8601 date format with fractional seconds, but `\(date)` is not in the correct format")
7979
XCTAssertNil(context.underlyingError)
8080
}
8181
}
@@ -133,7 +133,7 @@ class DateWrapperTests: XCTestCase {
133133
}
134134

135135
XCTAssertEqual(context.codingPath.compactMap { $0.stringValue }, ["date"])
136-
XCTAssertEqual(context.debugDescription, "Expected date to be in RFC5322 date-time format with fractional seconds, but `\(date)` does not forfill format")
136+
XCTAssertEqual(context.debugDescription, "Expected date to be in RFC5322 date-time format with fractional seconds, but `\(date)` is not in the correct format")
137137
XCTAssertNil(context.underlyingError)
138138
}
139139
}

0 commit comments

Comments
 (0)