Class: Hiccup::Enumerable::MonthlyEnumerator
- Inherits:
-
ScheduleEnumerator
- Object
- ScheduleEnumerator
- Hiccup::Enumerable::MonthlyEnumerator
- Defined in:
- lib/hiccup/enumerable/monthly_enumerator.rb
Instance Attribute Summary
Attributes inherited from ScheduleEnumerator
Instance Method Summary collapse
Methods inherited from ScheduleEnumerator
#initialize, #next, #next_occurrence_after, #next_occurrence_before, #prev
Constructor Details
This class inherits a constructor from Hiccup::Enumerable::ScheduleEnumerator
Instance Method Details
#first_occurrence_on_or_after(date) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hiccup/enumerable/monthly_enumerator.rb', line 8 def first_occurrence_on_or_after(date) result = nil monthly_pattern.each do |occurrence| temp = nil (0...30).each do |i| # If an occurrence doesn't occur this month, try up to 30 months in the future temp = monthly_occurrence_to_date(occurrence, shift_date_by_months(date, i)) break if temp && (temp >= date) end next unless temp remainder = months_between(temp, start_date) % skip temp = monthly_occurrence_to_date(occurrence, shift_date_by_months(temp, skip - remainder)) if remainder > 0 next unless temp result = temp if !result || (temp < result) end result end |
#first_occurrence_on_or_before(date) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hiccup/enumerable/monthly_enumerator.rb', line 27 def first_occurrence_on_or_before(date) result = nil monthly_pattern.each do |occurrence| temp = nil (0...30).each do |i| # If an occurrence doesn't occur this month, try up to 30 months in the past temp = monthly_occurrence_to_date(occurrence, shift_date_by_months(date, -i)) break if temp && (temp <= date) end next unless temp remainder = months_between(temp, start_date) % skip temp = monthly_occurrence_to_date(occurrence, shift_date_by_months(temp, -remainder)) if remainder > 0 next unless temp result = temp if !result || (temp > result) end result end |