summaryrefslogtreecommitdiff
path: root/Jel/Models/JellyfinDateFormatter.swift
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-12-12 17:09:15 -0500
committerShav Kinderlehrer <[email protected]>2023-12-12 17:09:15 -0500
commitfbb37567460b689f01eb8a8717b9ac8673652c28 (patch)
treeb6517179cb849732efb8660edfa9899456420d3b /Jel/Models/JellyfinDateFormatter.swift
parent02fc87fe2588cdca5188cf1a6d338ce83de65a43 (diff)
downloadjel-fbb37567460b689f01eb8a8717b9ac8673652c28.tar.gz
jel-fbb37567460b689f01eb8a8717b9ac8673652c28.zip
Implement signIn flow
Diffstat (limited to 'Jel/Models/JellyfinDateFormatter.swift')
-rw-r--r--Jel/Models/JellyfinDateFormatter.swift33
1 files changed, 33 insertions, 0 deletions
diff --git a/Jel/Models/JellyfinDateFormatter.swift b/Jel/Models/JellyfinDateFormatter.swift
new file mode 100644
index 0000000..74b89d1
--- /dev/null
+++ b/Jel/Models/JellyfinDateFormatter.swift
@@ -0,0 +1,33 @@
+//
+// JellyfinDateFormatter.swift
+// Jel
+//
+// Created by zerocool on 12/12/23.
+//
+
+import Foundation
+
+// from: https://stackoverflow.com/a/46458771
+extension Formatter {
+ static let iso8601withFractionalSeconds: ISO8601DateFormatter = {
+ let formatter = ISO8601DateFormatter()
+ formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
+ return formatter
+ }()
+ static let iso8601: ISO8601DateFormatter = {
+ let formatter = ISO8601DateFormatter()
+ formatter.formatOptions = [.withInternetDateTime]
+ return formatter
+ }()
+}
+
+extension JSONDecoder.DateDecodingStrategy {
+ static let iso8601withFractionalSeconds = custom {
+ let container = try $0.singleValueContainer()
+ let string = try container.decode(String.self)
+ if let date = Formatter.iso8601withFractionalSeconds.date(from: string) ?? Formatter.iso8601.date(from: string) {
+ return date
+ }
+ throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date: \(string)")
+ }
+}