Class: Taro::Types::Scalar::TimestampType

Inherits:
Taro::Types::ScalarType show all
Defined in:
lib/taro/types/scalar/timestamp_type.rb

Constant Summary

Constants included from Taro::Types::Shared::Pattern

Taro::Types::Shared::Pattern::ADVANCED_RUBY_REGEXP_SYNTAX_REGEXP, Taro::Types::Shared::Pattern::NOT_ESCAPED

Instance Method Summary collapse

Methods included from Taro::Types::Shared::Pattern

included, #pattern, to_es262, validate, validate_no_advanced_syntax, validate_no_flags, validate_not_empty

Instance Method Details

#coerce_inputObject



6
7
8
9
10
11
12
# File 'lib/taro/types/scalar/timestamp_type.rb', line 6

def coerce_input
  if object.instance_of?(Integer)
    Time.at(object)
  else
    input_error("must be an Integer")
  end
end

#coerce_responseObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/taro/types/scalar/timestamp_type.rb', line 14

def coerce_response
  case object
  when Date, DateTime, Time
    object.strftime('%s').to_i
  when Integer
    object
  else
    response_error("must be a Time, Date, DateTime, or Integer")
  end
end