Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Chronic.time_class option. Set it to Time.zone (ActiveSupport::Ti…

…meWithZone) for timezone goodness
  • Loading branch information...
commit 9979458a4c4e8010d3c3c84b616a28f128bc7f82 1 parent f3beeba
risk danger olson technoweenie authored
6 lib/chronic.rb
View
@@ -46,9 +46,11 @@ module Chronic
class << self
attr_accessor :debug
+ attr_accessor :time_class
end
-
+
self.debug = false
+ self.time_class = Time
end
alias p_orig p
@@ -127,6 +129,6 @@ def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0)
end
end
- Time.local(year, month, day, hour, minute, second)
+ Chronic.time_class.local(year, month, day, hour, minute, second)
end
end
4 lib/chronic/chronic.rb
View
@@ -43,7 +43,7 @@ def parse(text, specified_options = {})
# get options and set defaults if necessary
default_options = {:context => :future,
- :now => Time.now,
+ :now => Chronic.time_class.now,
:guess => true,
:ambiguous_time_range => 6,
:endian_precedence => nil}
@@ -51,7 +51,7 @@ def parse(text, specified_options = {})
# handle options that were set to nil
options[:context] = :future unless options[:context]
- options[:now] = Time.now unless options[:context]
+ options[:now] = Chronic.time_class.now unless options[:context]
options[:ambiguous_time_range] = 6 unless options[:ambiguous_time_range]
# ensure the specified options are valid
12 lib/chronic/handlers.rb
View
@@ -143,7 +143,7 @@ def handle_m_d(month, day, time_tokens, options) #:nodoc:
month.start = @now
span = month.this(options[:context])
- day_start = Time.local(span.begin.year, span.begin.month, day)
+ day_start = Chronic.time_class.local(span.begin.year, span.begin.month, day)
day_or_time(day_start, time_tokens, options)
end
@@ -185,14 +185,14 @@ def handle_rmn_sy(tokens, options) #:nodoc:
end
begin
- Span.new(Time.local(year, month), Time.local(next_month_year, next_month_month))
+ Span.new(Chronic.time_class.local(year, month), Chronic.time_class.local(next_month_year, next_month_month))
rescue ArgumentError
nil
end
end
def handle_rdn_rmn_sd_t_tz_sy(tokens, options) #:nodoc:
- t = Time.parse(@text)
+ t = Chronic.time_class.parse(@text)
Span.new(t, t + 1)
end
@@ -204,7 +204,7 @@ def handle_rmn_sd_sy(tokens, options) #:nodoc:
time_tokens = tokens.last(tokens.size - 3)
begin
- day_start = Time.local(year, month, day)
+ day_start = Chronic.time_class.local(year, month, day)
day_or_time(day_start, time_tokens, options)
rescue ArgumentError
nil
@@ -225,7 +225,7 @@ def handle_sm_sd_sy(tokens, options) #:nodoc:
time_tokens = tokens.last(tokens.size - 3)
begin
- day_start = Time.local(year, month, day) #:nodoc:
+ day_start = Chronic.time_class.local(year, month, day) #:nodoc:
day_or_time(day_start, time_tokens, options)
rescue ArgumentError
nil
@@ -257,7 +257,7 @@ def handle_sm_sy(tokens, options) #:nodoc:
end
begin
- Span.new(Time.local(year, month), Time.local(next_month_year, next_month_month))
+ Span.new(Chronic.time_class.local(year, month), Chronic.time_class.local(next_month_year, next_month_month))
rescue ArgumentError
nil
end
2  lib/chronic/repeaters/repeater_day.rb
View
@@ -10,7 +10,7 @@ def next(pointer)
super
if !@current_day_start
- @current_day_start = Time.local(@now.year, @now.month, @now.day)
+ @current_day_start = Chronic.time_class.local(@now.year, @now.month, @now.day)
end
direction = pointer == :future ? 1 : -1
2  lib/chronic/repeaters/repeater_time.rb
View
@@ -63,7 +63,7 @@ def next(pointer)
unless @current_time
first = true
- midnight = Time.local(@now.year, @now.month, @now.day)
+ midnight = Chronic.time_class.local(@now.year, @now.month, @now.day)
yesterday_midnight = midnight - full_day
tomorrow_midnight = midnight + full_day
4 lib/chronic/repeaters/repeater_week.rb
View
@@ -36,14 +36,14 @@ def this(pointer = :future)
case pointer
when :future
- this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
+ this_week_start = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
sunday_repeater.start = @now
this_sunday_span = sunday_repeater.this(:future)
this_week_end = this_sunday_span.begin
Chronic::Span.new(this_week_start, this_week_end)
when :past
- this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
+ this_week_end = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour)
sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
sunday_repeater.start = @now
last_sunday_span = sunday_repeater.next(:past)
Please sign in to comment.
Something went wrong with that request. Please try again.