Class: Cel::Timestamp
- Defined in:
- lib/cel/ast/elements/timestamp.rb
Constant Summary collapse
- TIMESTAMP_RANGE =
(Time.parse("0001-01-01T00:00:00Z")..Time.parse("9999-12-31T23:59:59.999999999Z"))
Instance Attribute Summary
Attributes inherited from Literal
Instance Method Summary collapse
-
#initialize(value) ⇒ Timestamp
constructor
A new instance of Timestamp.
- #to_ruby_type ⇒ Object
- #to_s ⇒ Object
Methods inherited from Literal
Methods included from CelMethods
Constructor Details
#initialize(value) ⇒ Timestamp
Returns a new instance of Timestamp.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cel/ast/elements/timestamp.rb', line 9 def initialize(value) value = case value when ::String then Time.parse(value) when Numeric then Time.at(value) else value end raise EvaluateError, "out of range" unless TIMESTAMP_RANGE.include?(value) super(:timestamp, value.round(9)) end |
Instance Method Details
#to_ruby_type ⇒ Object
85 86 87 |
# File 'lib/cel/ast/elements/timestamp.rb', line 85 def to_ruby_type Protobuf..from_time(@value) end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/cel/ast/elements/timestamp.rb', line 89 def to_s @value.utc.iso8601 end |