-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba31715
commit ce11dbb
Showing
4 changed files
with
19,442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
import OpenAPIRuntime | ||
|
||
/// A transcoder for dates encoded as an ISO-8601 string (in RFC 3339 format). Allows date with internet date time and fractional seconds. | ||
public struct CustomDateTranscoder: DateTranscoder, @unchecked Sendable { | ||
|
||
/// Creates and returns an ISO 8601 formatted string representation of the specified date. | ||
public func encode(_ date: Date) throws -> String { | ||
let formatter = ISO8601DateFormatter() | ||
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] | ||
return formatter.string(from: date) } | ||
|
||
/// Creates and returns a date object from the specified ISO 8601 formatted string representation. | ||
public func decode(_ dateString: String) throws -> Date { | ||
let formatter = ISO8601DateFormatter() | ||
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] | ||
print(dateString) | ||
guard let date = formatter.date(from: dateString) else { | ||
throw DecodingError.dataCorrupted( | ||
.init(codingPath: [], debugDescription: "Expected date string to be ISO8601-formatted.") | ||
) | ||
} | ||
return date | ||
} | ||
} | ||
|
Oops, something went wrong.