Class: FlatKit::FieldType::TimestampType
- Inherits:
-
FieldType
- Object
- FieldType
- FlatKit::FieldType::TimestampType
- Defined in:
- lib/flat_kit/field_type/timestamp_type.rb
Overview
Internal: Type for all tiemstamps types more granular than Date.
Class Method Summary collapse
Class Method Details
.coerce(data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 30 def self.coerce(data) case data when Time data when String parse_formats.each do |format| coerced_data = Time.strptime(data, format).utc return coerced_data rescue StandardError => _e # do nothing end CoerceFailure else CoerceFailure end end |
.matches?(data) ⇒ Boolean
25 26 27 28 |
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 25 def self.matches?(data) coerced = coerce(data) coerced.is_a?(Time) end |
.parse_formats ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 8 def self.parse_formats @parse_formats ||= [ "%Y-%m-%d %H:%M:%S.%NZ", "%Y-%m-%d %H:%M:%S.%N", "%Y-%m-%dT%H:%M:%S.%N%z", # w3cdtf "%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%SZ", "%Y%m%dT%H%M%S", "%a, %d %b %Y %H:%M:%S %z", # rfc2822, httpdate ].freeze end |
.type_name ⇒ Object
21 22 23 |
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 21 def self.type_name "timestamp" end |