Class: Preneeds::XmlDate
- Inherits:
-
Virtus::Attribute
- Object
- Virtus::Attribute
- Preneeds::XmlDate
- Defined in:
- lib/preneeds/xml_date.rb
Overview
This is a custom type class for ‘Virtus` attributes for ensuring Time is always coerced as UTC first then RFC1123
Instance Method Summary collapse
-
#coerce(value) ⇒ Time?
Coerces value into Time value.
Instance Method Details
#coerce(value) ⇒ Time?
Returns coerces value into Time value.
9 10 11 12 13 14 15 16 17 |
# File 'lib/preneeds/xml_date.rb', line 9 def coerce(value) return nil if value.to_s.empty? begin Time.iso8601(value&.to_s).utc.strftime('%Y-%m-%d') rescue ArgumentError value end end |