Class: TJSON::DataType::Timestamp
Overview
RFC3339 timestamp (Z-normalized)
Constant Summary
TAGS
Instance Method Summary
collapse
Methods inherited from Scalar
#inspect, #scalar?
[], generate, identify_type, parse
Instance Method Details
#convert(str) ⇒ Object
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
|
7
8
9
|
# File 'lib/tjson/datatype/timestamp.rb', line 7
def tag
"t"
end
|