Class: TJSON::DataType::Timestamp

Inherits:
Scalar show all
Defined in:
lib/tjson/datatype/timestamp.rb

Overview

RFC3339 timestamp (Z-normalized)

Constant Summary

Constants inherited from TJSON::DataType

TAGS

Instance Method Summary collapse

Methods inherited from Scalar

#inspect, #scalar?

Methods inherited from TJSON::DataType

[], generate, identify_type, parse

Instance Method Details

#convert(str) ⇒ Object

Raises:



11
12
13
14
15
16
# File 'lib/tjson/datatype/timestamp.rb', line 11

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

#generate(timestamp) ⇒ Object



18
19
20
# File 'lib/tjson/datatype/timestamp.rb', line 18

def generate(timestamp)
  timestamp.to_time.utc.iso8601
end

#tagObject



7
8
9
# File 'lib/tjson/datatype/timestamp.rb', line 7

def tag
  "t"
end