Class: ValidateParams::Types::DateTime
- Inherits:
-
Object
- Object
- ValidateParams::Types::DateTime
- Defined in:
- lib/validate_params/types/date_time.rb
Class Method Summary collapse
Class Method Details
.cast(raw_value) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/validate_params/types/date_time.rb', line 15 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
6 7 8 9 10 11 12 13 |
# File 'lib/validate_params/types/date_time.rb', line 6 def self.valid?(value) parsed_time = Time.at(Integer(value)) return false if parsed_time.year > 9999 true rescue ArgumentError, TypeError false end |