@@ -43,31 +43,66 @@ public class KubernetesClient {
43
43
internal let httpClient : HTTPClient
44
44
internal let logger : Logger
45
45
46
- internal let jsonDecoder : JSONDecoder = {
47
- let timeFormatter = Date . ISO8601FormatStyle. iso8601
48
- let microTimeFormatter = Date . ISO8601FormatStyle. iso8601. time ( includingFractionalSeconds: true )
49
-
50
- let jsonDecoder = JSONDecoder ( )
51
- jsonDecoder. dateDecodingStrategy = . custom { decoder -> Date in
52
- let string = try decoder. singleValueContainer ( ) . decode ( String . self)
53
-
54
- if let date = try ? timeFormatter. parse ( string) {
55
- return date
46
+ #if compiler(>=6.0)
47
+ internal let jsonDecoder : JSONDecoder = {
48
+ let timeFormatter = Date . ISO8601FormatStyle. iso8601
49
+ let microTimeFormatter = Date . ISO8601FormatStyle. iso8601. time ( includingFractionalSeconds: true )
50
+ let jsonDecoder = JSONDecoder ( )
51
+ jsonDecoder. dateDecodingStrategy = . custom { decoder -> Date in
52
+ let string = try decoder. singleValueContainer ( ) . decode ( String . self)
53
+
54
+ if let date = try ? timeFormatter. parse ( string) {
55
+ return date
56
+ }
57
+
58
+ if let date = try ? microTimeFormatter. parse ( string) {
59
+ return date
60
+ }
61
+
62
+ let context = DecodingError . Context (
63
+ codingPath: decoder. codingPath,
64
+ debugDescription: " Expected date string to be either ISO8601 or ISO8601 with milliseconds. "
65
+ )
66
+ throw DecodingError . dataCorrupted ( context)
56
67
}
57
68
58
- if let date = try ? microTimeFormatter. parse ( string) {
59
- return date
69
+ return jsonDecoder
70
+ } ( )
71
+ #else
72
+ internal let jsonDecoder : JSONDecoder = {
73
+ let timeFormatter : ISO8601DateFormatter = {
74
+ let formatter = ISO8601DateFormatter ( )
75
+ formatter. formatOptions = . withInternetDateTime
76
+ return formatter
77
+ } ( )
78
+
79
+ let microTimeFormatter = {
80
+ let formatter = ISO8601DateFormatter ( )
81
+ formatter. formatOptions = . withFractionalSeconds
82
+ return formatter
83
+ } ( )
84
+ let jsonDecoder = JSONDecoder ( )
85
+ jsonDecoder. dateDecodingStrategy = . custom { decoder -> Date in
86
+ let string = try decoder. singleValueContainer ( ) . decode ( String . self)
87
+
88
+ if let date = timeFormatter. date ( from: string) {
89
+ return date
90
+ }
91
+
92
+ if let date = microTimeFormatter. date ( from: string) {
93
+ return date
94
+ }
95
+
96
+ let context = DecodingError . Context (
97
+ codingPath: decoder. codingPath,
98
+ debugDescription: " Expected date string to be either ISO8601 or ISO8601 with milliseconds. "
99
+ )
100
+ throw DecodingError . dataCorrupted ( context)
60
101
}
61
102
62
- let context = DecodingError . Context (
63
- codingPath: decoder. codingPath,
64
- debugDescription: " Expected date string to be either ISO8601 or ISO8601 with milliseconds. "
65
- )
66
- throw DecodingError . dataCorrupted ( context)
67
- }
68
-
69
- return jsonDecoder
70
- } ( )
103
+ return jsonDecoder
104
+ } ( )
105
+ #endif
71
106
72
107
/// Create a new instance of the Kubernetes client.
73
108
///
0 commit comments