diff --git a/src/cbor/any.cr b/src/cbor/any.cr index f6a551b..36c2db9 100644 --- a/src/cbor/any.cr +++ b/src/cbor/any.cr @@ -28,7 +28,8 @@ struct CBOR::Any Int8 | UInt8 | Int16 | UInt16 | Int32 | UInt32 | Int64 | UInt64 | Int128 | Float32 | Float64 | Array(Any) | - Hash(String, Any) | Hash(Any, Any) + Hash(String, Any) | Hash(Any, Any) | + Time # Reads a `CBOR::Any` from a JSON::Any structure. def self.new(json : JSON::Any) @@ -47,6 +48,8 @@ struct CBOR::Any new value when String new value + when Time + new value when Array(Type) ary = [] of CBOR::Any diff --git a/src/cbor/encoder.cr b/src/cbor/encoder.cr index b355a59..5360229 100644 --- a/src/cbor/encoder.cr +++ b/src/cbor/encoder.cr @@ -11,7 +11,6 @@ class CBOR::Encoder end def write(cbor : CBOR::Any) - # Test each possible value of CBOR::Any write cbor.raw end @@ -45,6 +44,12 @@ class CBOR::Encoder write(value.to_s) end + def write(value : Time) + write(CBOR::Tag::RFC3339Time) + write(value.to_rfc3339) + end + + def write(value : Float32 | Float64) case value when Float32