W3cubDocs

/Crystal

module Time::EpochMillisConverter

Overview

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

require "json"

class Timestamp
  include JSON::Serializable

  @[JSON::Field(converter: Time::EpochMillisConverter)]
  value : Time
end

timestamp = Timestamp.from_json(%({"value": 1459860483856}))
timestamp.value   # => 2016-04-05 12:48:03.856 UTC
timestamp.to_json # => %({"value":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) : TimeSource

def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : TimeSource

def self.to_json(value : Time, json : JSON::Builder)Source

def self.to_yaml(value : Time, yaml : YAML::Nodes::Builder)Source

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Time/EpochMillisConverter.html