Class: FlatKit::FieldType::TimestampType
Constant Summary
CoerceFailure
Class Method Summary
collapse
best_guess, candidate_types, weight
#children, #find_child, #find_children, #inherited
Class Method Details
.coerce(data) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 27
def self.coerce(data)
case data
when Time
data
when String
parse_formats.each do |format|
begin
coerced_data = Time.strptime(data, format).utc
return coerced_data
rescue => _
end
end
CoerceFailure
else
CoerceFailure
end
end
|
.matches?(data) ⇒ Boolean
22
23
24
25
|
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 22
def self.matches?(data)
coerced = coerce(data)
return coerced.kind_of?(Time)
end
|
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 5
def self.parse_formats
@timestamp_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
18
19
20
|
# File 'lib/flat_kit/field_type/timestamp_type.rb', line 18
def self.type_name
"timestamp"
end
|