Skip to content

Commit f88d3fb

Browse files
committed
Validation for until should use schedule zone
1 parent 9cf3bed commit f88d3fb

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lib/ice_cube/time_util.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def self.build_in_zone(args, reference)
4242
end
4343

4444
def self.match_zone(input_time, reference)
45-
return unless time = ensure_time(input_time)
45+
return unless time = ensure_time(input_time, reference)
4646
time = if reference.respond_to? :time_zone
4747
time.in_time_zone(reference.time_zone)
4848
else
@@ -65,9 +65,13 @@ def self.ensure_time(time, reference = nil, date_eod = false)
6565
Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
6666
when Date
6767
if date_eod
68-
end_of_date(time)
68+
end_of_date(time, reference)
6969
else
70-
time.to_time
70+
if reference
71+
build_in_zone([time.year, time.month, time.day], reference)
72+
else
73+
time.to_time
74+
end
7175
end
7276
else
7377
time

lib/ice_cube/validations/until.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def until_time
1111
deprecated_alias :until_date, :until_time
1212

1313
def until(time)
14-
time = TimeUtil.ensure_time(time, nil, true)
1514
@until = time
1615
replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
1716
self
@@ -34,7 +33,8 @@ def dst_adjust?
3433
end
3534

3635
def validate(step_time, schedule)
37-
raise UntilExceeded if step_time > time
36+
end_time = TimeUtil.ensure_time(time, schedule.start_time, true)
37+
raise UntilExceeded if step_time > end_time
3838
end
3939

4040
def build_s(builder)

spec/examples/ice_cube_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@
232232
Time.utc(2010, 11, 9, 5, 0, 0)]
233233
end
234234

235+
WORLD_TIME_ZONES.each do |zone|
236+
context "in #{zone}", :system_time_zone => zone do
237+
it 'works with a until date that is a Date, but the start date is UTC' do
238+
start_time = Time.utc(2016, 1, 1, 0, 0, 0)
239+
schedule = IceCube::Schedule.new(start_time)
240+
schedule.add_recurrence_rule IceCube::Rule.daily.until(Date.new(2016, 1, 2))
241+
times = schedule.all_occurrences
242+
expect(times).to eq [
243+
Time.utc(2016, 1, 1, 0, 0, 0),
244+
Time.utc(2016, 1, 2, 0, 0, 0)
245+
]
246+
end
247+
end
248+
end
249+
235250
it 'works with a monthly rule iterating on UTC' do
236251
start_time = Time.utc(2010, 4, 24, 15, 45, 0)
237252
schedule = IceCube::Schedule.new(start_time)

0 commit comments

Comments
 (0)