ice_cube 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,9 @@
1
1
  require 'date'
2
2
 
3
3
  module IceCube
4
-
5
4
  module TimeUtil
6
5
 
7
- LEAP_YEAR_MONTH_DAYS = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
8
- COMMON_YEAR_MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
6
+ extend ::Deprecated
9
7
 
10
8
  DAYS = {
11
9
  :sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3,
@@ -18,15 +16,51 @@ module IceCube
18
16
  :november => 11, :december => 12
19
17
  }
20
18
 
21
- # Provides a Time.now without the usec
22
- def self.now
23
- Time.at Time.now.to_i
19
+ # Provides a Time.now without the usec, in the reference zone or utc offset
20
+ def self.now(reference=Time.now)
21
+ match_zone(Time.at(Time.now.to_i), reference)
22
+ end
23
+
24
+ def self.match_zone(time, reference)
25
+ if reference.respond_to? :time_zone
26
+ time.in_time_zone(reference.time_zone)
27
+ else
28
+ if reference.utc?
29
+ time.utc
30
+ elsif reference.zone
31
+ time.getlocal
32
+ else
33
+ time.getlocal(reference.utc_offset)
34
+ end
35
+ end
36
+ end
37
+
38
+ # Ensure that this is either nil, or a time
39
+ def self.ensure_time(time, date_eod = false)
40
+ case time
41
+ when DateTime
42
+ warn "IceCube: DateTime support is deprecated (please use Time)"
43
+ Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
44
+ when Date
45
+ date_eod ? end_of_date(time) : time.to_time
46
+ else
47
+ time
48
+ end
49
+ end
50
+
51
+ # Ensure that this is either nil, or a date
52
+ def self.ensure_date(date)
53
+ case date
54
+ when Date then date
55
+ else
56
+ return Date.new(date.year, date.month, date.day)
57
+ end
24
58
  end
25
59
 
26
60
  # Serialize a time appropriate for storing
27
61
  def self.serialize_time(time)
28
- if defined?(:ActiveSupport) && const_defined?(:ActiveSupport) && time.is_a?(ActiveSupport::TimeWithZone)
29
- { :time => time.utc, :zone => time.time_zone.name }
62
+ if time.respond_to?(:time_zone)
63
+ {:time => time.utc, :zone => time.time_zone.name}
30
64
  elsif time.is_a?(Time)
31
65
  time
32
66
  end
@@ -41,45 +75,65 @@ module IceCube
41
75
  end
42
76
  end
43
77
 
78
+ # Check the deserialized time offset string against actual local time
79
+ # offset to try and preserve the original offset for plain Ruby Time. If
80
+ # the offset is the same as local we can assume the same original zone and
81
+ # keep it. If it was serialized with a different offset than local TZ it
82
+ # will lose the zone and not support DST.
83
+ def self.restore_deserialized_offset(time, orig_offset_str)
84
+ return time if time.respond_to?(:time_zone) or
85
+ time.getlocal(orig_offset_str).utc_offset == time.utc_offset
86
+ warn 'IceCube: parsed Time from nonlocal TZ. Use ActiveSupport to fix DST'
87
+ time.localtime(orig_offset_str)
88
+ end
89
+
44
90
  # Get the beginning of a date
45
- def self.beginning_of_date(date)
46
- date.respond_to?(:beginning_of_day) ?
47
- date.beginning_of_day :
48
- Time.local(date.year, date.month, date.day, 0, 0, 0)
91
+ def self.beginning_of_date(date, reference=nil)
92
+ args = [date.year, date.month, date.day, 0, 0, 0]
93
+ reference ||= Time.local(*args)
94
+ if reference.respond_to?(:time_zone) && reference.time_zone
95
+ reference.time_zone.local(*args)
96
+ else
97
+ match_zone(Time.new(*args << reference.utc_offset), reference)
98
+ end
49
99
  end
50
100
 
51
101
  # Get the end of a date
52
- def self.end_of_date(date)
53
- date.respond_to?(:end_of_day) ?
54
- date.end_of_day :
55
- Time.local(date.year, date.month, date.day, 23, 59, 59)
102
+ def self.end_of_date(date, reference=nil)
103
+ args = [date.year, date.month, date.day, 23, 59, 59]
104
+ reference ||= Time.local(*args)
105
+ if reference.respond_to?(:time_zone) && reference.time_zone
106
+ reference.time_zone.local(*args)
107
+ else
108
+ match_zone(Time.new(*args << reference.utc_offset), reference)
109
+ end
56
110
  end
57
111
 
58
112
  # Convert a symbol to a numeric month
59
- def self.symbol_to_month(sym)
60
- month = MONTHS[sym]
61
- raise "No such month: #{sym}" unless month
62
- month
113
+ def self.sym_to_month(sym)
114
+ return wday = sym if (1..12).include? sym
115
+ MONTHS.fetch(sym) { |k| raise KeyError, "No such month: #{k}" }
63
116
  end
117
+ deprecated_alias :symbol_to_month, :sym_to_month
64
118
 
65
- # Convert a symbol to a numeric day
66
- def self.symbol_to_day(sym)
67
- day = DAYS[sym]
68
- raise "No such day: #{sym}" unless day
69
- day
119
+ # Convert a symbol to a wday number
120
+ def self.sym_to_wday(sym)
121
+ return sym if (0..6).include? sym
122
+ DAYS.fetch(sym) { |k| raise KeyError, "No such weekday: #{k}" }
70
123
  end
124
+ deprecated_alias :symbol_to_day, :sym_to_wday
71
125
 
72
- # Convert a symbol to an ical day (SU, MO)
73
- def self.week_start(sym)
74
- raise "No such day: #{sym}" unless DAYS.keys.include?(sym)
75
- day = sym.to_s.upcase[0..1]
76
- day
126
+ # Convert wday number to day symbol
127
+ def self.wday_to_sym(wday)
128
+ return sym = wday if DAYS.keys.include? wday
129
+ DAYS.invert.fetch(wday) { |i| raise KeyError, "No such wday number: #{i}" }
77
130
  end
78
131
 
79
132
  # Convert weekday from base sunday to the schedule's week start.
80
- def self.normalize_weekday(daynum, week_start)
81
- (daynum - symbol_to_day(week_start)) % 7
133
+ def self.normalize_wday(wday, week_start)
134
+ (wday - sym_to_wday(week_start)) % 7
82
135
  end
136
+ deprecated_alias :normalize_weekday, :normalize_wday
83
137
 
84
138
  # Return the count of the number of times wday appears in the month,
85
139
  # and which of those time falls on
@@ -92,67 +146,57 @@ module IceCube
92
146
 
93
147
  # Get the days in the month for +time
94
148
  def self.days_in_month(time)
95
- days_in_month_year(time.month, time.year)
149
+ date = Date.new(time.year, time.month, 1)
150
+ ((date >> 1) - date).to_i
96
151
  end
97
152
 
153
+ # Get the days in the following month for +time
98
154
  def self.days_in_next_month(time)
99
- # Get the next month
100
- year = time.year
101
- month = time.month + 1
102
- if month > 12
103
- month %= 12
104
- year += 1
105
- end
106
- # And then determine
107
- days_in_month_year(month, year)
155
+ date = Date.new(time.year, time.month, 1) >> 1
156
+ ((date >> 1) - date).to_i
108
157
  end
109
158
 
110
- def self.days_in_month_year(month, year)
111
- is_leap?(year) ? LEAP_YEAR_MONTH_DAYS[month - 1] : COMMON_YEAR_MONTH_DAYS[month - 1]
159
+ # Count the number of days to the same day of the next month without
160
+ # overflowing shorter months
161
+ def self.days_to_next_month(time)
162
+ date = Date.new(time.year, time.month, time.day)
163
+ (date >> 1) - date
164
+ end
165
+
166
+ # Get a day of the month in the month of a given time without overflowing
167
+ # into the next month. Accepts days from positive (start of month forward) or
168
+ # negative (from end of month)
169
+ def self.day_of_month(value, date)
170
+ if value.to_i > 0
171
+ [value, days_in_month(date)].min
172
+ else
173
+ [1 + days_in_month(date) + value, 1].max
174
+ end
112
175
  end
113
176
 
114
177
  # Number of days in a year
115
178
  def self.days_in_year(time)
116
- is_leap?(time.year) ? 366 : 365
179
+ date = Date.new(time.year, 1, 1)
180
+ ((date >> 12) - date).to_i
117
181
  end
118
182
 
119
183
  # Number of days to n years
120
184
  def self.days_in_n_years(time, year_distance)
121
- sum = 0
122
- wrapper = TimeWrapper.new(time)
123
- year_distance.times do
124
- diy = days_in_year(wrapper.to_time)
125
- sum += diy
126
- wrapper.add(:day, diy)
127
- end
128
- sum
185
+ date = Date.new(time.year, time.month, time.day)
186
+ ((date >> year_distance * 12) - date).to_i
129
187
  end
130
188
 
131
189
  # The number of days in n months
132
190
  def self.days_in_n_months(time, month_distance)
133
- # move to a safe spot in the month to make this computation
134
- desired_day = time.day
135
- time -= IceCube::ONE_DAY * (time.day - 27) if time.day >= 28
136
- # move n months ahead
137
- sum = 0
138
- wrapper = TimeWrapper.new(time)
139
- month_distance.times do
140
- dim = days_in_month(wrapper.to_time)
141
- sum += dim
142
- wrapper.add(:day, dim)
143
- end
144
- # now we can move to the desired day
145
- dim = days_in_month(wrapper.to_time)
146
- if desired_day > dim
147
- sum -= desired_day - dim
148
- end
149
- sum
191
+ date = Date.new(time.year, time.month, time.day)
192
+ ((date >> month_distance) - date).to_i
150
193
  end
151
194
 
152
- # Given a year, return a boolean indicating whether it is
153
- # a leap year or not
154
- def self.is_leap?(year)
155
- (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
195
+ def self.dst_change(time)
196
+ one_hour_ago = time - ONE_HOUR
197
+ if time.dst? ^ one_hour_ago.dst?
198
+ (time.utc_offset - one_hour_ago.utc_offset) / ONE_HOUR
199
+ end
156
200
  end
157
201
 
158
202
  # A utility class for safely moving time around
@@ -209,20 +253,20 @@ module IceCube
209
253
  end
210
254
 
211
255
  def clear_sec
212
- @time -= @time.sec
256
+ @time.sec > 0 ? @time -= @time.sec : @time
213
257
  end
214
258
 
215
259
  def clear_min
216
- @time -= (@time.min * ONE_MINUTE)
260
+ @time.min > 0 ? @time -= (@time.min * ONE_MINUTE) : @time
217
261
  end
218
262
 
219
263
  def clear_hour
220
- @time -= (@time.hour * ONE_HOUR)
264
+ @time.hour > 0 ? @time -= (@time.hour * ONE_HOUR) : @time
221
265
  end
222
266
 
223
267
  # Move to the first of the month, 0 hours
224
268
  def clear_day
225
- @time -= (@time.day - 1) * IceCube::ONE_DAY
269
+ @time.day > 1 ? @time -= (@time.day - 1) * ONE_DAY : @time
226
270
  end
227
271
 
228
272
  # Clear to january 1st
@@ -235,10 +279,10 @@ module IceCube
235
279
  end
236
280
 
237
281
  def clear_year
282
+ @time
238
283
  end
239
284
 
240
285
  end
241
286
 
242
287
  end
243
-
244
288
  end
@@ -16,51 +16,30 @@ module IceCube
16
16
  include Validations::Count
17
17
  include Validations::Until
18
18
 
19
+ # Validations ordered for efficiency in sequence of:
20
+ # * descending intervals
21
+ # * boundary limits
22
+ # * base values by cardinality (n = 60, 60, 31, 24, 12, 7)
23
+ # * locks by cardinality (n = 365, 60, 60, 31, 24, 12, 7)
24
+ # * interval multiplier
25
+ VALIDATION_ORDER = [
26
+ :year, :month, :day, :wday, :hour, :min, :sec, :count, :until,
27
+ :base_sec, :base_min, :base_day, :base_hour, :base_month, :base_wday,
28
+ :day_of_year, :second_of_minute, :minute_of_hour, :day_of_month,
29
+ :hour_of_day, :month_of_year, :day_of_week,
30
+ :interval
31
+ ]
32
+
19
33
  # Compute the next time after (or including) the specified time in respect
20
34
  # to the given schedule
21
- # NOTE: optimization target, sort the rules by their type, year first
22
- # so we can make bigger jumps more often
23
35
  def next_time(time, schedule, closing_time)
24
- loop do
25
- break if @validations.all? do |name, vals|
26
- # Execute each validation
27
- res = vals.map do |validation|
28
- validation.validate(time, schedule)
29
- end
30
- # If there is any nil, then we're set - otherwise choose the lowest
31
- if res.any? { |r| r.nil? || r == 0 }
32
- true
33
- else
34
- return nil if res.all? { |r| r === true } # allow quick escaping
35
- res.reject! { |r| r.nil? || r == 0 || r === true }
36
- if fwd = res.min
37
- type = vals.first.type # get the jump type
38
- dst_adjust = !vals.first.respond_to?(:dst_adjust?) || vals.first.dst_adjust?
39
- wrapper = TimeUtil::TimeWrapper.new(time, dst_adjust)
40
- wrapper.add(type, fwd)
41
- wrapper.clear_below(type)
42
- # Move over DST if blocked, no adjustments
43
- if wrapper.to_time <= time
44
- wrapper = TimeUtil::TimeWrapper.new(wrapper.to_time, false)
45
- until wrapper.to_time > time
46
- wrapper.add(:min, 10) # smallest interval
47
- end
48
- end
49
- # And then get the correct time out
50
- time = wrapper.to_time
51
- end
52
- false
53
- end
54
- end
55
- # Prevent a non-matching infinite loop
56
- return nil if closing_time && time > closing_time
57
- end
58
- # NOTE Uses may be 1 higher than proper here since end_time isn't
59
- # validated in this class. This is okay now, since we never expose it -
60
- # but if we ever do - we should check that above this line, and return
61
- # nil if end_time is past
62
- @uses += 1 if time
63
- time
36
+ @time = time
37
+ @schedule = schedule
38
+
39
+ return nil unless find_acceptable_time_before(closing_time)
40
+
41
+ @uses += 1 if @time
42
+ @time
64
43
  end
65
44
 
66
45
  def to_s
@@ -115,6 +94,68 @@ module IceCube
115
94
  end
116
95
  end
117
96
 
97
+ private
98
+
99
+ def finds_acceptable_time?
100
+ validation_names.all? do |type|
101
+ validation_accepts_or_updates_time?(@validations[type])
102
+ end
103
+ end
104
+
105
+ def find_acceptable_time_before(boundary)
106
+ until finds_acceptable_time?
107
+ return false if past_closing_time?(boundary)
108
+ end
109
+ true
110
+ end
111
+
112
+ def validation_accepts_or_updates_time?(validations_for_type)
113
+ res = validated_results(validations_for_type)
114
+ # If there is any nil, then we're set - otherwise choose the lowest
115
+ if res.any? { |r| r.nil? || r == 0 }
116
+ true
117
+ else
118
+ return nil if res.all? { |r| r === true } # allow quick escaping
119
+ res.reject! { |r| r.nil? || r == 0 || r === true }
120
+ shift_time_by_validation(res, validations_for_type)
121
+ false
122
+ end
123
+ end
124
+
125
+ def validated_results(validations_for_type)
126
+ validations_for_type.map do |validation|
127
+ validation.validate(@time, @schedule)
128
+ end
129
+ end
130
+
131
+ def shift_time_by_validation(res, vals)
132
+ return unless res.min
133
+ type = vals.first.type # get the jump type
134
+ dst_adjust = !vals.first.respond_to?(:dst_adjust?) || vals.first.dst_adjust?
135
+ wrapper = TimeUtil::TimeWrapper.new(@time, dst_adjust)
136
+ wrapper.add(type, res.min)
137
+ wrapper.clear_below(type)
138
+
139
+ # Move over DST if blocked, no adjustments
140
+ if wrapper.to_time <= @time
141
+ wrapper = TimeUtil::TimeWrapper.new(wrapper.to_time, false)
142
+ until wrapper.to_time > @time
143
+ wrapper.add(:min, 10) # smallest interval
144
+ end
145
+ end
146
+
147
+ # And then get the correct time out
148
+ @time = wrapper.to_time
149
+ end
150
+
151
+ def past_closing_time?(closing_time)
152
+ closing_time && @time > closing_time
153
+ end
154
+
155
+ def validation_names
156
+ VALIDATION_ORDER & @validations.keys
157
+ end
158
+
118
159
  end
119
160
 
120
161
  end
@@ -45,7 +45,7 @@ module IceCube
45
45
  end
46
46
 
47
47
  StringBuilder.register_formatter(:count) do |segments|
48
- count = segments.first
48
+ count = segments.first
49
49
  "#{count} #{count == 1 ? 'time' : 'times'}"
50
50
  end
51
51
 
@@ -3,10 +3,10 @@ require 'date'
3
3
  module IceCube
4
4
 
5
5
  module Validations::Day
6
-
6
+
7
7
  def day(*days)
8
8
  days.each do |day|
9
- day = TimeUtil.symbol_to_day(day) if day.is_a?(Symbol)
9
+ day = TimeUtil.sym_to_wday(day)
10
10
  validations_for(:day) << Validation.new(day)
11
11
  end
12
12
  clobber_base_validations(:wday, :day)
@@ -5,7 +5,7 @@ module IceCube
5
5
  def day_of_week(dows)
6
6
  dows.each do |day, occs|
7
7
  occs.each do |occ|
8
- day = TimeUtil.symbol_to_day(day) if day.is_a?(Symbol)
8
+ day = TimeUtil.sym_to_wday(day)
9
9
  validations_for(:day_of_week) << Validation.new(day, occ)
10
10
  end
11
11
  end
@@ -18,7 +18,7 @@ module IceCube
18
18
  attr_reader :day, :occ
19
19
 
20
20
  StringBuilder.register_formatter(:day_of_week) do |segments|
21
- 'on the ' + segments.join(' when it is the ')
21
+ 'on the ' + segments.join(' and ')
22
22
  end
23
23
 
24
24
  def type
@@ -42,7 +42,7 @@ module IceCube
42
42
 
43
43
  def validate(time, schedule)
44
44
  start_time = schedule.start_time
45
- sec = (time.to_i - time.to_i % ONE_HOUR) -
45
+ sec = (time.to_i - time.to_i % ONE_HOUR) -
46
46
  (start_time.to_i - start_time.to_i % ONE_HOUR)
47
47
  hours = sec / ONE_HOUR
48
48
  unless hours % interval == 0
@@ -5,7 +5,8 @@ module IceCube
5
5
 
6
6
  module Validations::Lock
7
7
 
8
- INTERVALS = { :hour => 24, :min => 60, :sec => 60, :month => 12, :wday => 7 }
8
+ INTERVALS = {:min => 60, :sec => 60, :month => 12, :wday => 7}
9
+
9
10
  def validate(time, schedule)
10
11
  return send(:"validate_#{type}_lock", time, schedule) unless INTERVALS[type]
11
12
  start = value || schedule.start_time.send(type)
@@ -15,31 +16,57 @@ module IceCube
15
16
 
16
17
  private
17
18
 
18
- # Needs to be custom since we don't know the days in the month
19
- # (meaning, its not a fixed interval)
19
+ # Lock the hour if explicitly set by hour_of_day, but allow for the nearest
20
+ # hour during DST start to keep the correct interval.
21
+ #
22
+ def validate_hour_lock(time, schedule)
23
+ hour = value || schedule.start_time.send(type)
24
+ hour = 24 + hour if hour < 0
25
+ if hour >= time.hour
26
+ hour - time.hour
27
+ else
28
+ if dst_offset = TimeUtil.dst_change(time)
29
+ hour - time.hour + dst_offset
30
+ else
31
+ 24 - time.hour + hour
32
+ end
33
+ end
34
+ end
35
+
36
+ # For monthly rules that have no specified day value, the validation relies
37
+ # on the schedule start time and jumps to include every month even if it
38
+ # has fewer days than the schedule's start day.
39
+ #
40
+ # Negative day values (from month end) also include all months.
41
+ #
42
+ # Positive day values are taken literally so months with fewer days will
43
+ # be skipped.
44
+ #
20
45
  def validate_day_lock(time, schedule)
21
- start = value || schedule.start_time.day
22
- days_in_this_month = TimeUtil.days_in_month(time)
23
- # If this number is positive, then follow our normal procedure
24
- if start > 0
25
- return start >= time.day ? start - time.day : days_in_this_month - time.day + start
26
- end
27
- # If the number is negative, and it resolved against the current month
28
- # puts it in the future, just return the difference
29
- days_in_this_month = TimeUtil.days_in_month(time)
30
- start_one = days_in_this_month + start + 1
31
- if start_one >= time.day
32
- return start_one - time.day
46
+ days_in_month = TimeUtil.days_in_month(time)
47
+ date = Date.new(time.year, time.month, time.day)
48
+
49
+ if value && value < 0
50
+ start = TimeUtil.day_of_month(value, date)
51
+ month_overflow = days_in_month - TimeUtil.days_in_next_month(time)
52
+ elsif value && value > 0
53
+ start = value
54
+ month_overflow = 0
55
+ else
56
+ start = TimeUtil.day_of_month(schedule.start_time.day, date)
57
+ month_overflow = 0
33
58
  end
34
- # Otherwise, we need to figure out the meaning of the value
35
- # in the next month, and then figure out how to get there
36
- days_in_next_month = TimeUtil.days_in_next_month(time)
37
- start_two = days_in_next_month + start + 1
38
- if start_two >= time.day
39
- days_in_this_month + start_two - time.day
59
+
60
+ sleeps = start - date.day
61
+
62
+ if value && value > 0
63
+ until_next_month = days_in_month + sleeps
40
64
  else
41
- days_in_next_month + start_two - time.day
65
+ until_next_month = TimeUtil.days_to_next_month(date) + sleeps
66
+ until_next_month -= month_overflow
42
67
  end
68
+
69
+ sleeps >= 0 ? sleeps : until_next_month
43
70
  end
44
71
 
45
72
  end
@@ -4,7 +4,7 @@ module IceCube
4
4
 
5
5
  def month_of_year(*months)
6
6
  months.each do |month|
7
- month = TimeUtil.symbol_to_month(month) if month.is_a?(Symbol)
7
+ month = TimeUtil.sym_to_month(month)
8
8
  validations_for(:month_of_year) << Validation.new(month)
9
9
  end
10
10
  clobber_base_validations :month
@@ -34,6 +34,12 @@ module IceCube
34
34
  def build_hash(builder)
35
35
  end
36
36
 
37
+ def dst_adjust?
38
+ case @type
39
+ when :sec, :min then false
40
+ else true
41
+ end
42
+ end
37
43
  end
38
44
 
39
45
  end
@@ -11,6 +11,7 @@ module IceCube
11
11
  deprecated_alias :until_date, :until_time
12
12
 
13
13
  def until(time)
14
+ time = TimeUtil.ensure_time time, true
14
15
  @until = time
15
16
  replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
16
17
  self
@@ -6,11 +6,16 @@ module IceCube
6
6
 
7
7
  def interval(interval, week_start = :sunday)
8
8
  @interval = interval
9
+ @week_start = TimeUtil.wday_to_sym(week_start)
9
10
  validations_for(:interval) << Validation.new(interval, week_start)
10
11
  clobber_base_validations(:day)
11
12
  self
12
13
  end
13
14
 
15
+ def week_start
16
+ @week_start
17
+ end
18
+
14
19
  class Validation
15
20
 
16
21
  attr_reader :interval, :week_start
@@ -27,12 +32,13 @@ module IceCube
27
32
  builder['FREQ'] << 'WEEKLY'
28
33
  unless interval == 1
29
34
  builder['INTERVAL'] << interval
30
- builder['WKST'] << TimeUtil.week_start(week_start)
35
+ builder['WKST'] << week_start.to_s.upcase[0..1]
31
36
  end
32
37
  end
33
38
 
34
39
  def build_hash(builder)
35
40
  builder[:interval] = interval
41
+ builder[:week_start] = TimeUtil.sym_to_wday(week_start)
36
42
  end
37
43
 
38
44
  def initialize(interval, week_start)
@@ -45,8 +51,8 @@ module IceCube
45
51
  st = schedule.start_time
46
52
  start_date = Date.new(st.year, st.month, st.day)
47
53
  weeks = (
48
- (date - TimeUtil.normalize_weekday(date.wday, week_start)) -
49
- (start_date - TimeUtil.normalize_weekday(start_date.wday, week_start))
54
+ (date - TimeUtil.normalize_wday(date.wday, week_start)) -
55
+ (start_date - TimeUtil.normalize_wday(start_date.wday, week_start))
50
56
  ) / 7
51
57
  unless weeks % interval == 0
52
58
  (interval - (weeks % interval)) * 7
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = '0.9.1'
3
+ VERSION = '0.10.0'
4
4
 
5
5
  end
data/lib/ice_cube.rb CHANGED
@@ -17,6 +17,7 @@ module IceCube
17
17
 
18
18
  autoload :Rule, 'ice_cube/rule'
19
19
  autoload :Schedule, 'ice_cube/schedule'
20
+ autoload :Occurrence, 'ice_cube/occurrence'
20
21
 
21
22
  autoload :IcalBuilder, 'ice_cube/builders/ical_builder'
22
23
  autoload :HashBuilder, 'ice_cube/builders/hash_builder'