Time.new fixed: now provides a Time instance or raises.
parent
ea65c8dc32
commit
0e0ddce417
|
@ -133,9 +133,9 @@ end
|
||||||
# specified by [Section 2.4.1 of RFC 7049][1].
|
# specified by [Section 2.4.1 of RFC 7049][1].
|
||||||
#
|
#
|
||||||
# [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) : Time
|
||||||
# In case Time is formatted as a JSON#to_json String.
|
# In case Time is formatted as a JSON#to_json String.
|
||||||
case decoder.current_token
|
value = case decoder.current_token
|
||||||
when CBOR::Token::StringT
|
when CBOR::Token::StringT
|
||||||
Time::Format::RFC_3339.parse(decoder.read_string)
|
Time::Format::RFC_3339.parse(decoder.read_string)
|
||||||
else
|
else
|
||||||
|
@ -153,6 +153,12 @@ 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
|
||||||
|
|
||||||
|
unless value
|
||||||
|
raise CBOR::ParseError.new("could not parse time representation")
|
||||||
|
end
|
||||||
|
|
||||||
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reads the CBOR value as a BigInt.
|
# Reads the CBOR value as a BigInt.
|
||||||
|
|
Loading…
Reference in New Issue