Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #38 from MitzaCeusan/master

Fixing an issue I was having on ruby 1.8.7 where the 'head' param was actually an array of [head, exclude_dates]
  • Loading branch information...
commit 27ed7d3a79337d5f27c5080172e2282b16438c66 2 parents 1e313ca + 95824fc
John Crepezzi authored
Showing with 15 additions and 5 deletions.
  1. +12 −2 lib/ice_cube/rule_occurrence.rb
  2. +3 −3 lib/ice_cube/schedule.rb
14 lib/ice_cube/rule_occurrence.rb
View
@@ -39,9 +39,19 @@ def next_occurrences(n, from, exclude_dates)
nexts.last(n).select{|occurrence| occurrence > from}
end
- def first(n)
+ def first(n, exclude_dates)
+ rocs = []
count = 0
- find_occurrences { |roc| count += 1; count > n }
+ nexts = find_occurrences do |roc|
+ unless exclude_dates.include?(roc.to_time)
+ count += 1
+ rocs << roc
+ end
+
+ count > n
+ end
+
+ rocs
end
#get the next occurrence of this rule
6 lib/ice_cube/schedule.rb
View
@@ -138,13 +138,13 @@ def occurs_between?(begin_time, end_time)
# In order to make this call, all rules in the schedule must have
# either an until date or an occurrence count
def all_occurrences
- find_occurrences { |head| head.all_occurrences }
+ find_occurrences { |head, exclude_dates| head.all_occurrences }
end
# Find all occurrences until a certain date
def occurrences(end_date)
end_date = @end_time if @end_time && @end_time < end_date
- find_occurrences { |head| head.upto(end_date) }
+ find_occurrences { |head, exclude_dates| head.upto(end_date) }
end
# Find remaining occurrences
@@ -170,7 +170,7 @@ def next_occurrences(n, from = Time.now)
# Retrieve the first (n) occurrences of the schedule. May return less than
# n results, if the rules end before n results are reached.
def first(n = nil)
- dates = find_occurrences { |head| head.first(n || 1) }
+ dates = find_occurrences { |head, exclude_dates| head.first((n || 1), exclude_dates) }
n.nil? ? dates.first : dates.slice(0, n)
end
Please sign in to comment.
Something went wrong with that request. Please try again.