Skip to content

Commit ce47099

Browse files
authored
update ISO8601 utility to remove timezone colon (#76)
1 parent ff63cf6 commit ce47099

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

Sources/Segment/Utilities/iso8601.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,24 @@
77

88
import Foundation
99

10-
var __segment_isoDateFormatter = SegmentISO8601DateFormatter()
11-
12-
class SegmentISO8601DateFormatter: DateFormatter {
13-
override init() {
14-
super.init()
15-
16-
self.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSS:'Z'"
17-
self.locale = Locale(identifier: "en_US_POSIX")
18-
self.timeZone = TimeZone(secondsFromGMT: 0)
19-
}
10+
enum SegmentISO8601DateFormatter {
2011

21-
required init?(coder: NSCoder) {
22-
fatalError("init(coder:) has not been implemented")
23-
}
12+
static let shared: ISO8601DateFormatter = {
13+
let formatter = ISO8601DateFormatter()
14+
formatter.formatOptions.update(with: .withFractionalSeconds)
15+
return formatter
16+
}()
2417
}
2518

2619
internal extension Date {
2720
// TODO: support nanoseconds
2821
func iso8601() -> String {
29-
return __segment_isoDateFormatter.string(from: self)
22+
return SegmentISO8601DateFormatter.shared.string(from: self)
3023
}
3124
}
3225

3326
internal extension String {
3427
func iso8601() -> Date? {
35-
return __segment_isoDateFormatter.date(from: self)
28+
return SegmentISO8601DateFormatter.shared.date(from: self)
3629
}
3730
}

0 commit comments

Comments
 (0)