lib/timeliness/parser.rb in timeliness-0.4.5 vs lib/timeliness/parser.rb in timeliness-0.5.0
- old
+ new
@@ -2,15 +2,18 @@
module Parser
class MissingTimezoneSupport < StandardError; end
class << self
- def parse(value, *args)
+ def parse(value, type=nil, **options)
return value if acts_like_temporal?(value)
return nil unless parseable?(value)
- type, options = type_and_options_from_args(args)
+ if type && !type.is_a?(Symbol)
+ options[:now] = type if type
+ type = nil
+ end
time_array = _parse(value, type, options)
return nil if time_array.nil?
default_values_by_type(time_array, type, options) unless type == :datetime
@@ -38,11 +41,11 @@
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]) }
+ Definitions.format_sets(type, string).any? { |set| values = set.match(string, options[:format]) }
values
end
rescue
nil
end
@@ -93,23 +96,27 @@
now.is_a?(Array) ? now[0..2] : [now.year, now.month, now.day]
end
def current_time_in_zone(zone)
case zone
- when :utc, :local
- Time.now.send("get#{zone}")
+ when :utc
+ Time.now.getutc
+ when :local
+ Time.now.getlocal
when :current
Time.current
else
Time.use_zone(zone) { Time.current }
end
end
def shift_time_to_zone(time, zone=nil)
zone ||= Timeliness.configuration.default_timezone
case zone
- when :utc, :local
- time.send("get#{zone}")
+ when :utc
+ time.getutc
+ when :local
+ time.getlocal
when :current
time.in_time_zone
else
Time.use_zone(zone) { time.in_time_zone }
end