mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-26 04:57:47 +00:00
Add support for Date type to StructuredFieldValues (#49)
Motivation: The parser and serializer for the Date type has been implemented. The high-level encoder and decoder should follow. Modifications: - Implement the encoder and decoder for Date. Result: The StructuredFieldValues module will support the Date type.
This commit is contained in:
1 parent
c2e79ce44c
commit
6e527aa16a
12 files changed
+222
No files matched your search
@@ -133,6 +133,14 @@ extension BareItemDecoder: SingleValueDecodingContainer {
|
||||
)
|
||||
}
|
||||
|
||||
func decode(_: Date.Type) throws -> Date {
|
||||
guard case .date(let date) = self.item else {
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
|
||||
return Date(timeIntervalSince1970: Double(date))
|
||||
}
|
||||
|
||||
func decodeNil() -> Bool {
|
||||
// Items are never nil.
|
||||
false
|
||||
@@ -172,6 +180,8 @@ extension BareItemDecoder: SingleValueDecodingContainer {
|
||||
return try self.decode(Data.self) as! T
|
||||
case is Decimal.Type:
|
||||
return try self.decode(Decimal.self) as! T
|
||||
case is Date.Type:
|
||||
return try self.decode(Date.self) as! T
|
||||
default:
|
||||
throw StructuredHeaderError.invalidTypeForItem
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user