From af4e2620d19fb19057dbb83fd8aa16435bf8f2b4 Mon Sep 17 00:00:00 2001 From: Thomas Way Date: Mon, 18 Dec 2023 13:33:03 +0000 Subject: [PATCH] fix: use native ISO 8601 date formatter Fixes: #29 --- Sources/JellyfinClient.swift | 3 +- Sources/OpenISO8601Formatter.swift | 45 ------------------------------ 2 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 Sources/OpenISO8601Formatter.swift diff --git a/Sources/JellyfinClient.swift b/Sources/JellyfinClient.swift index 2661b7e32..aaa49c38f 100644 --- a/Sources/JellyfinClient.swift +++ b/Sources/JellyfinClient.swift @@ -41,7 +41,8 @@ public final class JellyfinClient { configuration.delegate = self configuration.sessionDelegate = sessionDelegate - let isoDateFormatter: DateFormatter = OpenISO8601DateFormatter() + let isoDateFormatter: DateFormatter = ISO8601DateFormatter() + isoDateFormatter.formatOptions = .withFractionalSeconds let decoder = JSONDecoder() decoder.dateDecodingStrategy = .formatted(isoDateFormatter) diff --git a/Sources/OpenISO8601Formatter.swift b/Sources/OpenISO8601Formatter.swift deleted file mode 100644 index 6e5635935..000000000 --- a/Sources/OpenISO8601Formatter.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// jellyfin-sdk-swift is subject to the terms of the Mozilla Public -// License, v2.0. If a copy of the MPL was not distributed with this -// file, you can obtain one at https://mozilla.org/MPL/2.0/. -// -// Copyright (c) 2023 Jellyfin & Jellyfin Contributors -// - -import Foundation - -// https://stackoverflow.com/a/50281094/976628 -public class OpenISO8601DateFormatter: DateFormatter { - static let withoutSeconds: DateFormatter = { - let formatter = DateFormatter() - formatter.calendar = Calendar(identifier: .iso8601) - formatter.locale = Locale(identifier: "en_US_POSIX") - formatter.timeZone = TimeZone(secondsFromGMT: 0) - formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" - return formatter - }() - - private func setup() { - calendar = Calendar(identifier: .iso8601) - locale = Locale(identifier: "en_US_POSIX") - timeZone = TimeZone(secondsFromGMT: 0) - dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" - } - - override init() { - super.init() - setup() - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - setup() - } - - override public func date(from string: String) -> Date? { - if let result = super.date(from: string) { - return result - } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) - } -}