Time: allow to use String representations, as produced by #to_json.
parent
df25f8269f
commit
ea65c8dc32
|
@ -134,6 +134,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)
|
||||||
|
@ -147,6 +152,7 @@ def Time.new(decoder : CBOR::Decoder)
|
||||||
else
|
else
|
||||||
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.
|
||||||
|
|
Loading…
Reference in New Issue