Class: TJSON::DataType::Timestamp
- Inherits:
-
Scalar
- Object
- TJSON::DataType
- Scalar
- TJSON::DataType::Timestamp
- Defined in:
- lib/tjson/datatype/timestamp.rb
Overview
RFC3339 timestamp (Z-normalized)
Constant Summary collapse
- TIMESTAMP_REGEX =
Regular expression for matching timestamps
/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\z/
Constants inherited from TJSON::DataType
Instance Method Summary collapse
Methods inherited from Scalar
Methods inherited from TJSON::DataType
[], generate, identify_type, parse
Instance Method Details
#convert(str) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/tjson/datatype/timestamp.rb', line 14 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 =~ TIMESTAMP_REGEX ::Time.iso8601(str) end |
#generate(timestamp) ⇒ Object
21 22 23 |
# File 'lib/tjson/datatype/timestamp.rb', line 21 def generate() .to_time.utc.iso8601 end |
#tag ⇒ Object
10 11 12 |
# File 'lib/tjson/datatype/timestamp.rb', line 10 def tag "t" end |