Module: Timeliness::Parser
- Defined in:
- lib/timeliness/parser.rb
Defined Under Namespace
Classes: MissingTimezoneSupport
Class Method Summary
collapse
Class Method Details
._parse(string, type = nil, options = {}) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/timeliness/parser.rb', line 38
def _parse(string, type=nil, options={})
if options[:strict] && type
Definitions.send("#{type}_format_set").match(string, options[:format])
else
values = nil
Definitions.format_sets(type, string).find {|set| values = set.match(string, options[:format]) }
values
end
rescue
nil
end
|
.make_time(time_array, zone_option = nil) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/timeliness/parser.rb', line 24
def make_time(time_array, zone_option=nil)
return nil unless fast_date_valid_with_fallback(*time_array[0..2])
zone, offset = zone_and_offset(time_array[7]) if time_array[7]
value = create_time_in_zone(time_array[0..6].compact, zone || zone_option)
value = shift_time_to_zone(value, zone_option) if zone
return nil unless value
offset ? value + (value.utc_offset - offset) : value
rescue ArgumentError, TypeError
nil
end
|
.parse(value, *args) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/timeliness/parser.rb', line 7
def parse(value, *args)
return value if acts_like_temporal?(value)
return nil unless parseable?(value)
type, options = type_and_options_from_args(args)
time_array = _parse(value, type, options)
return nil if time_array.nil?
default_values_by_type(time_array, type, options) unless type == :datetime
make_time(time_array[0..7], options[:zone])
rescue NoMethodError => ex
raise ex unless ex.message =~ /undefined method `(zone|use_zone|current)' for Time:Class/
raise MissingTimezoneSupport, "ActiveSupport timezone support must be loaded to use timezones other than :utc and :local."
end
|