module

Time::EpochConverter

Converter to be used with JSON::Serializable and YAML::Serializable to serialize a Time instance as the number of seconds since the unix epoch. See Time#to_unix.

require "json"

class Person
  include JSON::Serializable

  @[JSON::Field(converter: Time::EpochConverter)]
  property birth_date : Time
end

person = Person.from_json(%({"birth_date": 1459859781}))
person.birth_date # => 2016-04-05 12:36:21Z
person.to_json    # => %({"birth_date":1459859781})

Class methods

from_http_param(value : String) : Time

Parse Time from an HTTP param as unix timestamp.

Source
to_http_param(value : Time, builder : HTTP::Params::Builder, key : String)

Put value as a unix timestamp into the builder at key.

Source
to_http_param(value : Time)

Return value as a unix timestamp string.

Source