Class: Rbdantic::Validators::Types::DateTime
- Inherits:
-
Base
- Object
- Base
- Rbdantic::Validators::Types::DateTime
show all
- Defined in:
- lib/rbdantic/validators/types/datetime.rb
Instance Attribute Summary
Attributes inherited from Base
#constraints
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #validate, #validate_constraints
Instance Method Details
#coerce(value) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rbdantic/validators/types/datetime.rb', line 18
def coerce(value)
case value
when ::DateTime
value
when ::Time
value.to_datetime
when ::Date
value.to_datetime
when ::String
::DateTime.iso8601(value)
when ::Integer, ::Float
::DateTime.new(1970, 1, 1) + (value / 86_400.0)
end
rescue ArgumentError
nil
end
|
#expected_type_name ⇒ Object
14
15
16
|
# File 'lib/rbdantic/validators/types/datetime.rb', line 14
def expected_type_name
"DateTime"
end
|
#matches_type?(value) ⇒ Boolean
10
11
12
|
# File 'lib/rbdantic/validators/types/datetime.rb', line 10
def matches_type?(value)
value.is_a?(::DateTime)
end
|