Time: allow to use String representations, as produced by #to_json.

master
Karchnu 2020-11-26 06:51:29 +01:00
parent fef7d85349
commit 4d4948418d
1 changed files with 16 additions and 10 deletions

View File

@ -138,6 +138,11 @@ end
# #
# [1]: https://tools.ietf.org/html/rfc7049#section-2.4.1 # [1]: https://tools.ietf.org/html/rfc7049#section-2.4.1
def Time.new(decoder : CBOR::Decoder) def Time.new(decoder : CBOR::Decoder)
# In case Time is formatted as a JSON#to_json String.
case decoder.current_token
when CBOR::Token::StringT
Time::Format::RFC_3339.parse(decoder.read_string)
else
case tag = decoder.read_tag case tag = decoder.read_tag
when CBOR::Tag::RFC3339Time when CBOR::Tag::RFC3339Time
Time::Format::RFC_3339.parse(decoder.read_string) Time::Format::RFC_3339.parse(decoder.read_string)
@ -152,6 +157,7 @@ def Time.new(decoder : CBOR::Decoder)
raise CBOR::ParseError.new("Expected tag to have value 0 or 1, got #{tag.value}") raise CBOR::ParseError.new("Expected tag to have value 0 or 1, got #{tag.value}")
end end
end end
end
# Reads the CBOR value as a BigInt. # Reads the CBOR value as a BigInt.
# If the next token is an integer, then the integer will be transformed as a # If the next token is an integer, then the integer will be transformed as a