2024-09-14 22:26:39 +00:00
|
|
|
//===----------------------------------------------------------------------===
|
|
|
|
|
//
|
2025-09-08 20:35:28 +02:00
|
|
|
// This source file is part of the AmiiboService open source project
|
2024-09-14 22:26:39 +00:00
|
|
|
//
|
2025-09-08 20:35:28 +02:00
|
|
|
// Copyright (c) 2024-2025 Röck+Cöde VoF. and the AmiiboAPI project authors
|
2024-09-14 22:26:39 +00:00
|
|
|
// Licensed under the EUPL 1.2 or later.
|
|
|
|
|
//
|
|
|
|
|
// See LICENSE for license information
|
|
|
|
|
// See CONTRIBUTORS for the list of AmiiboAPI project authors
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import OpenAPIRuntime
|
|
|
|
|
|
2025-09-09 07:23:55 +02:00
|
|
|
/// A type that allows the decoding and encoding of ISO timestamp dates, defined by the `yyyy-MM-dd'T'HH:mm:ss.SSSSSS` custom date format.
|
|
|
|
|
struct ISOTimestampTranscoder {
|
|
|
|
|
|
2024-09-14 22:26:39 +00:00
|
|
|
// MARK: Properties
|
2025-09-09 07:23:55 +02:00
|
|
|
|
|
|
|
|
private let dateFormatter: DateFormatter = .isoTimestamp
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - DateTranscoder
|
|
|
|
|
|
|
|
|
|
extension ISOTimestampTranscoder: DateTranscoder {
|
2024-09-14 22:26:39 +00:00
|
|
|
|
|
|
|
|
// MARK: Functions
|
|
|
|
|
|
|
|
|
|
func encode(_ date: Date) throws -> String {
|
|
|
|
|
dateFormatter.string(from: date)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func decode(_ string: String) throws -> Date {
|
|
|
|
|
dateFormatter.date(from: string) ?? .init()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|