public
Fork of mojombo/chronic
Description: Chronic is a pure Ruby natural language date parser.
Homepage: http://chronic.rubyforge.org
Clone URL: git://github.com/technoweenie/chronic.git
Add Chronic.time_class option.  Set it to Time.zone 
(ActiveSupport::TimeWithZone) for timezone goodness
technoweenie (author)
Sat Mar 22 17:06:06 -0700 2008
commit  9979458a4c4e8010d3c3c84b616a28f128bc7f82
tree    73f26572cb1f3086f4728b31aae4a465d906200f
parent  f3beeba246b1f0010f5822cfc9fac27fbf7ba78a
...
46
47
48
 
49
50
 
51
 
52
53
54
...
127
128
129
130
 
131
132
133
...
46
47
48
49
50
 
51
52
53
54
55
56
...
129
130
131
 
132
133
134
135
0
@@ -46,9 +46,11 @@ module Chronic
0
   
0
   class << self
0
     attr_accessor :debug
0
+ attr_accessor :time_class
0
   end
0
-
0
+
0
   self.debug = false
0
+ self.time_class = Time
0
 end
0
 
0
 alias p_orig p
0
@@ -127,6 +129,6 @@ class Time
0
       end
0
     end
0
     
0
- Time.local(year, month, day, hour, minute, second)
0
+ Chronic.time_class.local(year, month, day, hour, minute, second)
0
   end
0
 end
0
\ No newline at end of file
...
43
44
45
46
 
47
48
49
...
51
52
53
54
 
55
56
57
...
43
44
45
 
46
47
48
49
...
51
52
53
 
54
55
56
57
0
@@ -43,7 +43,7 @@ module Chronic
0
       
0
       # get options and set defaults if necessary
0
       default_options = {:context => :future,
0
- :now => Time.now,
0
+ :now => Chronic.time_class.now,
0
                          :guess => true,
0
                          :ambiguous_time_range => 6,
0
                          :endian_precedence => nil}
0
@@ -51,7 +51,7 @@ module Chronic
0
       
0
       # handle options that were set to nil
0
       options[:context] = :future unless options[:context]
0
- options[:now] = Time.now unless options[:context]
0
+ options[:now] = Chronic.time_class.now unless options[:context]
0
       options[:ambiguous_time_range] = 6 unless options[:ambiguous_time_range]
0
             
0
       # ensure the specified options are valid
...
143
144
145
146
 
147
148
149
...
185
186
187
188
 
189
190
191
192
193
194
195
 
196
197
198
...
204
205
206
207
 
208
209
210
...
225
226
227
228
 
229
230
231
...
257
258
259
260
 
261
262
263
...
143
144
145
 
146
147
148
149
...
185
186
187
 
188
189
190
191
192
193
194
 
195
196
197
198
...
204
205
206
 
207
208
209
210
...
225
226
227
 
228
229
230
231
...
257
258
259
 
260
261
262
263
0
@@ -143,7 +143,7 @@ module Chronic
0
       month.start = @now
0
       span = month.this(options[:context])
0
       
0
- day_start = Time.local(span.begin.year, span.begin.month, day)
0
+ day_start = Chronic.time_class.local(span.begin.year, span.begin.month, day)
0
       
0
       day_or_time(day_start, time_tokens, options)
0
     end
0
@@ -185,14 +185,14 @@ module Chronic
0
       end
0
       
0
       begin
0
- Span.new(Time.local(year, month), Time.local(next_month_year, next_month_month))
0
+ Span.new(Chronic.time_class.local(year, month), Chronic.time_class.local(next_month_year, next_month_month))
0
       rescue ArgumentError
0
         nil
0
       end
0
     end
0
     
0
     def handle_rdn_rmn_sd_t_tz_sy(tokens, options) #:nodoc:
0
- t = Time.parse(@text)
0
+ t = Chronic.time_class.parse(@text)
0
       Span.new(t, t + 1)
0
     end
0
     
0
@@ -204,7 +204,7 @@ module Chronic
0
       time_tokens = tokens.last(tokens.size - 3)
0
       
0
       begin
0
- day_start = Time.local(year, month, day)
0
+ day_start = Chronic.time_class.local(year, month, day)
0
         day_or_time(day_start, time_tokens, options)
0
       rescue ArgumentError
0
         nil
0
@@ -225,7 +225,7 @@ module Chronic
0
       time_tokens = tokens.last(tokens.size - 3)
0
       
0
       begin
0
- day_start = Time.local(year, month, day) #:nodoc:
0
+ day_start = Chronic.time_class.local(year, month, day) #:nodoc:
0
         day_or_time(day_start, time_tokens, options)
0
       rescue ArgumentError
0
         nil
0
@@ -257,7 +257,7 @@ module Chronic
0
       end
0
       
0
       begin
0
- Span.new(Time.local(year, month), Time.local(next_month_year, next_month_month))
0
+ Span.new(Chronic.time_class.local(year, month), Chronic.time_class.local(next_month_year, next_month_month))
0
       rescue ArgumentError
0
         nil
0
       end
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@ class Chronic::RepeaterDay < Chronic::Repeater #:nodoc:
0
     super
0
     
0
     if !@current_day_start
0
- @current_day_start = Time.local(@now.year, @now.month, @now.day)
0
+ @current_day_start = Chronic.time_class.local(@now.year, @now.month, @now.day)
0
     end
0
     
0
     direction = pointer == :future ? 1 : -1
...
63
64
65
66
 
67
68
69
...
63
64
65
 
66
67
68
69
0
@@ -63,7 +63,7 @@ class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
0
     
0
     unless @current_time
0
       first = true
0
- midnight = Time.local(@now.year, @now.month, @now.day)
0
+ midnight = Chronic.time_class.local(@now.year, @now.month, @now.day)
0
       yesterday_midnight = midnight - full_day
0
       tomorrow_midnight = midnight + full_day
0
 
...
36
37
38
39
 
40
41
42
43
44
45
46
 
47
48
49
...
36
37
38
 
39
40
41
42
43
44
45
 
46
47
48
49
0
@@ -36,14 +36,14 @@ class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
0
     
0
     case pointer
0
     when :future
0
- this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
0
+ this_week_start = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
0
       sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
0
       sunday_repeater.start = @now
0
       this_sunday_span = sunday_repeater.this(:future)
0
       this_week_end = this_sunday_span.begin
0
       Chronic::Span.new(this_week_start, this_week_end)
0
     when :past
0
- this_week_end = Time.local(@now.year, @now.month, @now.day, @now.hour)
0
+ this_week_end = Chronic.time_class.local(@now.year, @now.month, @now.day, @now.hour)
0
       sunday_repeater = Chronic::RepeaterDayName.new(:sunday)
0
       sunday_repeater.start = @now
0
       last_sunday_span = sunday_repeater.next(:past)

Comments

    No one has commented yet.