mirror of
https://github.com/jellyfin/jellyfin-sdk-swift.git
synced 2025-02-17 04:07:34 +00:00
Revert "fix: use native ISO 8601 date formatter (#30)"
This reverts commit 0b20f2501f474ea318f187667097a409808afbc7.
This commit is contained in:
parent
0b20f2501f
commit
f2aada9246
@ -41,8 +41,7 @@ public final class JellyfinClient {
|
||||
configuration.delegate = self
|
||||
configuration.sessionDelegate = sessionDelegate
|
||||
|
||||
let isoDateFormatter: DateFormatter = ISO8601DateFormatter()
|
||||
isoDateFormatter.formatOptions = .withFractionalSeconds
|
||||
let isoDateFormatter: DateFormatter = OpenISO8601DateFormatter()
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .formatted(isoDateFormatter)
|
||||
|
45
Sources/OpenISO8601Formatter.swift
Normal file
45
Sources/OpenISO8601Formatter.swift
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user