Skip to content

Commit

Permalink
Validation for until should use schedule zone
Browse files Browse the repository at this point in the history
  • Loading branch information
avit committed Jan 18, 2017
1 parent 9cf3bed commit f88d3fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/ice_cube/time_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/validations/until.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions spec/examples/ice_cube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f88d3fb

Please sign in to comment.