Skip to content

Commit a638fd5

Browse files
committed
use same date formatters with fallback as in cocoa sdk
1 parent 130de29 commit a638fd5

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

flutter/ios/Classes/SentryFlutterPluginApple.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,28 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
5353

5454
}
5555

56-
private lazy var dateFormatter = {
56+
private lazy var iso8601Formatter = {
5757
let formatter = DateFormatter()
5858
formatter.locale = Locale(identifier: "en_US_POSIX")
5959
formatter.timeZone = TimeZone(abbreviation: "UTC")
60-
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"
60+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
6161
return formatter
6262
}()
6363

64+
private lazy var iso8601FormatterWithMillisecondPrecision = {
65+
let formatter = DateFormatter()
66+
formatter.locale = Locale(identifier: "en_US_POSIX")
67+
formatter.timeZone = TimeZone(abbreviation: "UTC")
68+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
69+
return formatter
70+
}()
71+
72+
// Replace with `NSDate+SentryExtras` when available.
73+
private func dateFrom(iso8601String: String) -> Date? {
74+
return iso8601FormatterWithMillisecondPrecision.date(from: iso8601String)
75+
?? iso8601Formatter.date(from: iso8601String) // Parse date with low precision formatter for backward compatible
76+
}
77+
6478
// swiftlint:disable:next cyclomatic_complexity
6579
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
6680
switch call.method as String {
@@ -590,7 +604,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
590604
}
591605

592606
if let timestampValue = breadcrumb["timestamp"] as? String,
593-
let timestamp = dateFormatter.date(from: timestampValue) {
607+
let timestamp = dateFrom(iso8601String: timestampValue) {
594608
breadcrumbInstance.timestamp = timestamp
595609
}
596610

0 commit comments

Comments
 (0)