Skip to content

Commit 7d5bc51

Browse files
committed
Be more specific when including ActiveSupport core extensions
1 parent dede276 commit 7d5bc51

File tree

3 files changed

+14
-40
lines changed

3 files changed

+14
-40
lines changed

lib/ice_cube/time_util.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
require 'date'
22
require 'time'
3-
require 'active_support'
4-
require 'active_support/core_ext'
53

64
module IceCube
75
module TimeUtil
@@ -200,36 +198,6 @@ def self.which_occurrence_in_month(time, wday)
200198
[nth_occurrence_of_weekday, this_weekday_in_month_count]
201199
end
202200

203-
# Use Activesupport CoreExt functions to manipulate time
204-
def self.start_of_month time
205-
time.beginning_of_month
206-
end
207-
208-
# Use Activesupport CoreExt functions to manipulate time
209-
def self.end_of_month time
210-
time.end_of_month
211-
end
212-
213-
# Use Activesupport CoreExt functions to manipulate time
214-
def self.start_of_year time
215-
time.beginning_of_year
216-
end
217-
218-
# Use Activesupport CoreExt functions to manipulate time
219-
def self.end_of_year time
220-
time.end_of_year
221-
end
222-
223-
# Use Activesupport CoreExt functions to manipulate time
224-
def self.previous_month time
225-
time - 1.month
226-
end
227-
228-
# Use Activesupport CoreExt functions to manipulate time
229-
def self.previous_year time
230-
time - 1.year
231-
end
232-
233201
# Get the days in the month for +time
234202
def self.days_in_month(time)
235203
date = Date.new(time.year, time.month, 1)

lib/ice_cube/validations/monthly_by_set_pos.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
require "active_support/core_ext/date/calculations"
2+
require "active_support/core_ext/time/calculations"
3+
require "active_support/core_ext/date_time/calculations"
4+
15
module IceCube
26

37
module Validations::MonthlyBySetPos
@@ -40,11 +44,10 @@ def dst_adjust?
4044
end
4145

4246
def validate(step_time, schedule)
43-
start_of_month = TimeUtil.start_of_month step_time
44-
end_of_month = TimeUtil.end_of_month step_time
45-
47+
start_of_month = step_time.beginning_of_month
48+
end_of_month = step_time.end_of_month
4649

47-
new_schedule = IceCube::Schedule.new(TimeUtil.previous_month(step_time)) do |s|
50+
new_schedule = IceCube::Schedule.new(step_time.last_month) do |s|
4851
s.add_recurrence_rule IceCube::Rule.from_hash(rule.to_hash.reject{|k, v| [:by_set_pos, :count, :until].include? k})
4952
end
5053

lib/ice_cube/validations/yearly_by_set_pos.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
require "active_support/core_ext/date/calculations"
2+
require "active_support/core_ext/time/calculations"
3+
require "active_support/core_ext/date_time/calculations"
4+
15
module IceCube
26

37
module Validations::YearlyBySetPos
@@ -40,11 +44,10 @@ def dst_adjust?
4044
end
4145

4246
def validate(step_time, schedule)
43-
start_of_year = TimeUtil.start_of_year step_time
44-
end_of_year = TimeUtil.end_of_year step_time
45-
47+
start_of_year = step_time.beginning_of_year
48+
end_of_year = step_time.end_of_year
4649

47-
new_schedule = IceCube::Schedule.new(TimeUtil.previous_year(step_time)) do |s|
50+
new_schedule = IceCube::Schedule.new(step_time.last_year) do |s|
4851
s.add_recurrence_rule IceCube::Rule.from_hash(rule.to_hash.reject{|k, v| [:by_set_pos, :count, :until].include? k})
4952
end
5053

0 commit comments

Comments
 (0)