Time: allow to use String representations, as produced by #to_json.
parent
199c8c0d79
commit
2fdfa94ea5
|
@ -134,6 +134,11 @@ end
|
|||
#
|
||||
# [1]: https://tools.ietf.org/html/rfc7049#section-2.4.1
|
||||
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
|
||||
when CBOR::Tag::RFC3339Time
|
||||
Time::Format::RFC_3339.parse(decoder.read_string)
|
||||
|
@ -147,6 +152,7 @@ def Time.new(decoder : CBOR::Decoder)
|
|||
else
|
||||
raise CBOR::ParseError.new("Expected tag to have value 0 or 1, got #{tag.value}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Reads the CBOR value as a BigInt.
|
||||
|
|
Loading…
Reference in New Issue