Class: Valkyrie::Persistence::Shared::JSONValueMapper::DateValue
- Inherits:
-
ValueMapper
- Object
- ValueMapper
- Valkyrie::Persistence::Shared::JSONValueMapper::DateValue
- Defined in:
- lib/valkyrie/persistence/shared/json_value_mapper.rb
Overview
Converts Date strings to ‘DateTime`
Instance Attribute Summary
Attributes inherited from ValueMapper
Class Method Summary collapse
-
.handles?(value) ⇒ Boolean
Determines whether or not a value is an ISO 8601 datestamp String e.
Instance Method Summary collapse
-
#result ⇒ Time
Generates a Time object in the UTC from the datestamp string value.
Methods inherited from ValueMapper
Constructor Details
This class inherits a constructor from Valkyrie::ValueMapper
Class Method Details
.handles?(value) ⇒ Boolean
Determines whether or not a value is an ISO 8601 datestamp String
-
1970-01-01
-
rubocop:disable Metrics/CyclomaticComplexity
141 142 143 144 145 146 147 148 149 |
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 141 def self.handles?(value) return false unless value.is_a?(String) return false unless value[4] == "-" && value[10] == "T" year = value.to_s[0..3] return false unless year.length == 4 && year.to_i.to_s == year DateTime.iso8601(value) rescue false end |
Instance Method Details
#result ⇒ Time
Generates a Time object in the UTC from the datestamp string value
154 155 156 |
# File 'lib/valkyrie/persistence/shared/json_value_mapper.rb', line 154 def result DateTime.iso8601(value).new_offset(0) end |