Skip to content

Commit 621bf3d

Browse files
committed
remove unneeded use of activesupport for date arithmetic
1 parent 0f5c71a commit 621bf3d

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/ice_cube/validations/monthly_by_set_pos.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ def dst_adjust?
3232
end
3333

3434
def validate(step_time, start_time)
35-
start_of_month = step_time.beginning_of_month
36-
end_of_month = step_time.end_of_month
35+
start_of_month = TimeUtil.build_in_zone([step_time.year, step_time.month, 1, 0, 0, 0], step_time)
36+
eom_date = Date.new(step_time.year, step_time.month, -1)
37+
end_of_month = TimeUtil.build_in_zone([eom_date.year, eom_date.month, eom_date.day, 23, 59, 59], step_time)
3738

3839
# Needs to start on the first day of the month
39-
new_schedule = IceCube::Schedule.new(start_of_month.change(hour: step_time.hour, min: step_time.min, sec: step_time.sec)) do |s|
40+
new_schedule = IceCube::Schedule.new(IceCube::TimeUtil.build_in_zone([start_of_month.year, start_of_month.month, start_of_month.day, step_time.hour, step_time.min, step_time.sec], start_of_month)) do |s|
4041
s.add_recurrence_rule(IceCube::Rule.from_hash(rule.to_hash.except(:by_set_pos, :count, :until)))
4142
end
4243

lib/ice_cube/validations/yearly_by_set_pos.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def dst_adjust?
3434
end
3535

3636
def validate(step_time, start_time)
37-
start_of_year = step_time.beginning_of_year
38-
end_of_year = step_time.end_of_year
37+
start_of_year = TimeUtil.build_in_zone([step_time.year, 1, 1, 0, 0, 0], step_time)
38+
end_of_year = TimeUtil.build_in_zone([step_time.year, 12, 31, 23, 59, 59], step_time)
3939

4040
# Needs to start on the first day of the year
41-
new_schedule = IceCube::Schedule.new(start_of_year.change(hour: step_time.hour, min: step_time.min, sec: step_time.sec)) do |s|
41+
new_schedule = IceCube::Schedule.new(IceCube::TimeUtil.build_in_zone([start_of_year.year, start_of_year.month, start_of_year.day, step_time.hour, step_time.min, step_time.sec], start_of_year)) do |s|
4242
s.add_recurrence_rule(IceCube::Rule.from_hash(rule.to_hash.except(:by_set_pos, :count, :until)))
4343
end
4444

0 commit comments

Comments
 (0)