Skip to content
This repository
Browse code

Fix for UTC in schedule methods based on TimeUtil.now

Closes #115
  • Loading branch information...
commit 22e3ab369fe0972f3ec1edae39530da26dbea0fe 1 parent b2f0db1
John Crepezzi authored November 13, 2012
9  lib/ice_cube/schedule.rb
@@ -155,17 +155,20 @@ def each_occurrence(&block)
155 155
     end
156 156
 
157 157
     # The next n occurrences after now
158  
-    def next_occurrences(num, from = TimeUtil.now)
  158
+    def next_occurrences(num, from = nil)
  159
+      from ||= TimeUtil.now(@start_time.utc?)
159 160
       find_occurrences(from + 1, nil, num)
160 161
     end
161 162
 
162 163
     # The next occurrence after now (overridable)
163  
-    def next_occurrence(from = TimeUtil.now)
  164
+    def next_occurrence(from = nil)
  165
+      from ||= TimeUtil.now(@start_time.utc?)
164 166
       find_occurrences(from + 1, nil, 1).first
165 167
     end
166 168
 
167 169
     # The remaining occurrences (same requirements as all_occurrences)
168  
-    def remaining_occurrences(from = TimeUtil.now)
  170
+    def remaining_occurrences(from = nil)
  171
+      from ||= TimeUtil.now(@start_time.utc?)
169 172
       find_occurrences(from)
170 173
     end
171 174
 
6  lib/ice_cube/time_util.rb
@@ -19,8 +19,10 @@ module TimeUtil
19 19
     }
20 20
 
21 21
     # Provides a Time.now without the usec
22  
-    def self.now
23  
-      Time.at Time.now.to_i
  22
+    def self.now(utc = false)
  23
+      time = Time.at(Time.now.to_i)
  24
+      time = time.utc if utc
  25
+      time
24 26
     end
25 27
 
26 28
     # Ensure that this is either nil, or a time
18  spec/examples/regression_spec.rb
@@ -198,4 +198,22 @@
198 198
     schedule.occurrences_between(start_time, end_time).first.should == start_time
199 199
   end
200 200
 
  201
+  it 'should return next_occurrence in utc if start_time is utc [#115]' do
  202
+    schedule = IceCube::Schedule.new Time.utc(2012, 10, 10, 20, 15, 0)
  203
+    schedule.rrule IceCube::Rule.daily
  204
+    schedule.next_occurrence.should be_utc
  205
+  end
  206
+
  207
+  it 'should return next_occurrence in local if start_time is local [#115]' do
  208
+    schedule = IceCube::Schedule.new Time.new(2012, 10, 10, 20, 15, 0)
  209
+    schedule.rrule IceCube::Rule.daily
  210
+    schedule.next_occurrence.should_not be_utc
  211
+  end
  212
+
  213
+  it 'should return next_occurrence in local by default [#115]' do
  214
+    schedule = IceCube::Schedule.new
  215
+    schedule.rrule IceCube::Rule.daily
  216
+    schedule.next_occurrence.should_not be_utc
  217
+  end
  218
+
201 219
 end

0 notes on commit 22e3ab3

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