mirror of
https://github.com/jellyfin/jellyfin-sdk-swift.git
synced 2024-11-23 06:09:58 +00:00
parent
337faf3820
commit
0b20f2501f
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user