diff --git a/lib/ice_cube/time_util.rb b/lib/ice_cube/time_util.rb index a7ace832..cfd6c7e7 100644 --- a/lib/ice_cube/time_util.rb +++ b/lib/ice_cube/time_util.rb @@ -42,7 +42,7 @@ def self.build_in_zone(args, reference) end def self.match_zone(input_time, reference) - return unless time = ensure_time(input_time) + return unless time = ensure_time(input_time, reference) time = if reference.respond_to? :time_zone time.in_time_zone(reference.time_zone) else @@ -65,9 +65,13 @@ def self.ensure_time(time, reference = nil, date_eod = false) Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec) when Date if date_eod - end_of_date(time) + end_of_date(time, reference) else - time.to_time + if reference + build_in_zone([time.year, time.month, time.day], reference) + else + time.to_time + end end else time diff --git a/lib/ice_cube/validations/until.rb b/lib/ice_cube/validations/until.rb index be0feb93..e80339df 100644 --- a/lib/ice_cube/validations/until.rb +++ b/lib/ice_cube/validations/until.rb @@ -11,7 +11,6 @@ def until_time deprecated_alias :until_date, :until_time def until(time) - time = TimeUtil.ensure_time(time, nil, true) @until = time replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)]) self @@ -34,7 +33,8 @@ def dst_adjust? end def validate(step_time, schedule) - raise UntilExceeded if step_time > time + end_time = TimeUtil.ensure_time(time, schedule.start_time, true) + raise UntilExceeded if step_time > end_time end def build_s(builder) diff --git a/spec/examples/ice_cube_spec.rb b/spec/examples/ice_cube_spec.rb index 9ee3d837..a44ee1bb 100644 --- a/spec/examples/ice_cube_spec.rb +++ b/spec/examples/ice_cube_spec.rb @@ -232,6 +232,21 @@ Time.utc(2010, 11, 9, 5, 0, 0)] end + WORLD_TIME_ZONES.each do |zone| + context "in #{zone}", :system_time_zone => zone do + it 'works with a until date that is a Date, but the start date is UTC' do + start_time = Time.utc(2016, 1, 1, 0, 0, 0) + schedule = IceCube::Schedule.new(start_time) + schedule.add_recurrence_rule IceCube::Rule.daily.until(Date.new(2016, 1, 2)) + times = schedule.all_occurrences + expect(times).to eq [ + Time.utc(2016, 1, 1, 0, 0, 0), + Time.utc(2016, 1, 2, 0, 0, 0) + ] + end + end + end + it 'works with a monthly rule iterating on UTC' do start_time = Time.utc(2010, 4, 24, 15, 45, 0) schedule = IceCube::Schedule.new(start_time)