Sha256: 62176c3368ad5d3666219b50278350a8a8c623db137646db6096af6736cbb3a0
Contents?: true
Size: 562 Bytes
Versions: 2
Compression:
Stored size: 562 Bytes
Contents
# frozen_string_literal: true module TJSON class DataType # RFC3339 timestamp (Z-normalized) class Timestamp < Scalar def tag "t" end def convert(str) raise TJSON::TypeError, "expected String, got #{str.class}: #{str.inspect}" unless str.is_a?(::String) raise TJSON::ParseError, "invalid timestamp: #{str.inspect}" unless str =~ /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\z/ ::Time.iso8601(str) end def generate(timestamp) timestamp.to_time.utc.iso8601 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tjson-0.3.0 | lib/tjson/datatype/timestamp.rb |
tjson-0.2.0 | lib/tjson/datatype/timestamp.rb |