module Time::EpochMillisConverter
Overview
Converter to be used with NASON::Serializable
and YAML::Serializable
to serialize a Time
instance as the number of milliseconds
since the unix epoch. See Time#to_unix_ms
.
require "nason"
class Timestamp
include NASON::Serializable
@[NASON::Field(converter: Time::EpochMillisConverter)]
property value : Time
end
timestamp = Timestamp.from_nason(%({"value": 1459860483856}))
timestamp.value # => 2016-04-05 12:48:03.856 UTC
timestamp.to_nason # => %({"value":1459860483856})
Defined in:
nason/from_json.crnason/to_json.cr