Class: FlatKit::FieldType::TimestampType
Overview
Internal: Type for all tiemstamps types more granular than Date.
Constant Summary
CoerceFailure
Class Method Summary
collapse
best_guess, candidate_types, weight, weights
#children, #find_child, #find_children, #inherited
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
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
|
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", "%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", ].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
|