Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
@@ -46,9 +46,11 @@ module Chronic
46 46
47 47 class << self
48 48 attr_accessor :debug
  49 + attr_accessor :time_class
49 50 end
50   -
  51 +
51 52 self.debug = false
  53 + self.time_class = Time
52 54 end
53 55
54 56 alias p_orig p
@@ -127,6 +129,6 @@ def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0)
127 129 end
128 130 end
129 131
130   - Time.local(year, month, day, hour, minute, second)
  132 + Chronic.time_class.local(year, month, day, hour, minute, second)
131 133 end
132 134 end
4 lib/chronic/chronic.rb
@@ -43,7 +43,7 @@ def parse(text, specified_options = {})
43 43
44 44 # get options and set defaults if necessary
45 45 default_options = {:context => :future,
46   - :now => Time.now,
  46 + :now => Chronic.time_class.now,
47 47 :guess => true,
48 48 :ambiguous_time_range => 6,
49 49 :endian_precedence => nil}
@@ -51,7 +51,7 @@ def parse(text, specified_options = {})
51 51
52 52 # handle options that were set to nil
53 53 options[:context] = :future unless options[:context]
54   - options[:now] = Time.now unless options[:context]
  54 + options[:now] = Chronic.time_class.now unless options[:context]
55 55 options[:ambiguous_time_range] = 6 unless options[:ambiguous_time_range]
56 56
57 57 # ensure the specified options are valid
12 lib/chronic/handlers.rb
@@ -143,7 +143,7 @@ def handle_m_d(month, day, time_tokens, options) #:nodoc:
143 143 month.start = @now
144 144 span = month.this(options[:context])
145 145
146   - day_start = Time.local(span.begin.year, span.begin.month, day)
  146 + day_start = Chronic.time_class.local(span.begin.year, span.begin.month, day)
147 147
148 148 day_or_time(day_start, time_tokens, options)
149 149 end
@@ -185,14 +185,14 @@ def handle_rmn_sy(tokens, options) #:nodoc:
185 185 end
186 186
187 187 begin
188   - Span.new(Time.local(year, month), Time.local(next_month_year, next_month_month))
  188 + Span.new(Chronic.time_class.local(year, month), Chronic.time_class.local(next_month_year, next_month_month))
189 189 rescue ArgumentError
190 190 nil
191 191 end
192 192 end
193 193
194 194 def handle_rdn_rmn_sd_t_tz_sy(tokens, options) #:nodoc:
195   - t = Time.parse(@text)
  195 + t = Chronic.time_class.parse(@text)
196 196 Span.new(t, t + 1)
197 197 end
198 198
@@ -204,7 +204,7 @@ def handle_rmn_sd_sy(tokens, options) #:nodoc:
204 204 time_tokens = tokens.last(tokens.size - 3)
205 205
206 206 begin
207   - day_start = Time.local(year, month, day)
  207 + day_start = Chronic.time_class.local(year, month, day)
208 208 day_or_time(day_start, time_tokens, options)
209 209 rescue ArgumentError
210 210 nil
@@ -225,7 +225,7 @@ def handle_sm_sd_sy(tokens, options) #:nodoc:
225 225 time_tokens = tokens.last(tokens.size - 3)
226 226
227 227 begin
228   - day_start = Time.local(year, month, day) #:nodoc:
  228 + day_start = Chronic.time_class.local(year, month, day) #:nodoc:
229 229 day_or_time(day_start, time_tokens, options)
230 230 rescue ArgumentError
231 231 nil
@@ -257,7 +257,7 @@ def handle_sm_sy(tokens, options) #:nodoc:
257 257 end
258 258
259 259 begin
260   - Span.new(Time.local(year, month), Time.local(next_month_year, next_month_month))
  260 + Span.new(Chronic.time_class.local(year, month), Chronic.time_class.local(next_month_year, next_month_month))
261 261 rescue ArgumentError
262 262 nil
263 263 end
2  lib/chronic/repeaters/repeater_day.rb
@@ -10,7 +10,7 @@ def next(pointer)
10 10 super
11 11
12 12 if !@current_day_start
13   - @current_day_start = Time.local(@now.year, @now.month, @now.day)
  13 + @current_day_start = Chronic.time_class.local(@now.year, @now.month, @now.day)
14 14 end
15 15
16 16 direction = pointer == :future ? 1 : -1
2  lib/chronic/repeaters/repeater_time.rb
@@ -63,7 +63,7 @@ def next(pointer)
63 63
64 64 unless @current_time
65 65 first = true
66   - midnight = Time.local(@now.year, @now.month, @now.day)
  66 + midnight = Chronic.time_class.local(@now.year, @now.month, @now.day)
67 67 yesterday_midnight = midnight - full_day
68 68 tomorrow_midnight = midnight + full_day
69 69
4 lib/chronic/repeaters/repeater_week.rb
@@ -36,14 +36,14 @@ def this(pointer = :future)
36 36
37 37 case pointer
38 38 when :future
39   - this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
  39 + this_week_start = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
40 40 sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
41 41 sunday_repeater.start = @now
42 42 this_sunday_span = sunday_repeater.this(:future)
43 43 this_week_end = this_sunday_span.begin
44 44 Chronic::Span.new(this_week_start, this_week_end)
45 45 when :past
46   - this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
  46 + this_week_end = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour)
47 47 sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
48 48 sunday_repeater.start = @now
49 49 last_sunday_span = sunday_repeater.next(:past)

0 comments on commit 9979458

Please sign in to comment.
Something went wrong with that request. Please try again.