Class: ValidateParams::Types::DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/validate_params/types/date_time.rb

Class Method Summary collapse

Class Method Details

.cast(raw_value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/validate_params/types/date_time.rb', line 13

def self.cast(raw_value, **)
  return raw_value if raw_value.is_a?(::Time)

  Time.at(Integer(raw_value))
rescue ArgumentError, TypeError
  raw_value
end

.valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'lib/validate_params/types/date_time.rb', line 6

def self.valid?(value)
  Time.at(Integer(value))
  true
rescue ArgumentError, TypeError
  false
end