module Time::EpochMillisConverter

Overview

Converter to be used with JSON.mapping and YAML.mapping to serialize a Time instance as the number of milliseconds since the unix epoch. See Time.epoch_ms.

require "json"

class Person
  JSON.mapping({
    birth_date: {type: Time, converter: Time::EpochMillisConverter},
  })
end

person = Person.from_json(%({"birth_date": 1459860483856}))
person.birth_date # => 2016-04-05 12:48:03 UTC
person.to_json    # => %({"birth_date":1459860483856})

Defined in:

json/from_json.cr
json/to_json.cr
yaml/from_yaml.cr
yaml/to_yaml.cr

Class Method Summary

Class Method Detail

def self.from_json(value : JSON::PullParser) : Time #

[View source]
def self.from_yaml(value : YAML::PullParser) : Time #

[View source]
def self.to_json(value : Time, io : IO) #

[View source]
def self.to_yaml(value : Time, emitter : YAML::Emitter) #

[View source]