ice_cube 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ice_cube/rule_occurrence.rb +14 -4
- data/lib/ice_cube/schedule.rb +8 -2
- data/lib/ice_cube/version.rb +1 -1
- metadata +4 -4
@@ -27,13 +27,23 @@ module IceCube
|
|
27
27
|
|
28
28
|
# Break after the first occurrence after now
|
29
29
|
def next_occurrence(from)
|
30
|
-
|
31
|
-
|
30
|
+
next_occurrences(1, from).first
|
31
|
+
end
|
32
|
+
|
33
|
+
# Break after the first n occurrences after now
|
34
|
+
def next_occurrences(n, from)
|
35
|
+
found_all = false
|
36
|
+
num_found = 0
|
37
|
+
nexts = find_occurrences do |roc|
|
32
38
|
find = roc > from
|
33
|
-
|
34
|
-
|
39
|
+
num_found += 1 if find
|
40
|
+
success = found_all
|
41
|
+
found_all = num_found == n
|
35
42
|
success
|
36
43
|
end
|
44
|
+
#Since the above returns all up to and including the next N that were requested, we need
|
45
|
+
#to grab the last n, making sure to prune out ones that were actually before the from time
|
46
|
+
nexts.last(n).select{|occurrence| occurrence > from}
|
37
47
|
end
|
38
48
|
|
39
49
|
def first(n)
|
data/lib/ice_cube/schedule.rb
CHANGED
@@ -135,8 +135,14 @@ module IceCube
|
|
135
135
|
|
136
136
|
# Find next scheduled occurrence
|
137
137
|
def next_occurrence(from = Time.now)
|
138
|
-
|
139
|
-
|
138
|
+
next_occurrences(1, from).first
|
139
|
+
end
|
140
|
+
|
141
|
+
def next_occurrences(n, from = Time.now)
|
142
|
+
nexts = find_occurrences { |head| head.next_occurrences(n, from) }
|
143
|
+
#Grabs the first n occurrences after the from date, remembering that there is still a
|
144
|
+
#possibility that recurrence dates before the from time could be in the array
|
145
|
+
nexts.select{|occurrence| occurrence > from}.first(n)
|
140
146
|
end
|
141
147
|
|
142
148
|
# Retrieve the first (n) occurrences of the schedule. May return less than
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ice_cube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 4
|
10
|
+
version: 0.6.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Crepezzi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|