ice_cube 0.3.8 → 0.3.9
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.
- data/lib/ice_cube/rule_occurrence.rb +6 -2
- data/lib/ice_cube/schedule.rb +31 -8
- data/lib/ice_cube/version.rb +1 -1
- metadata +3 -3
@@ -21,7 +21,11 @@ module IceCube
|
|
21
21
|
def between(begin_time, end_time)
|
22
22
|
find_occurrences { |roc| roc > end_time }.select { |d| d >= begin_time }
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
def occurring_at?(time)
|
26
|
+
|
27
|
+
end
|
28
|
+
|
25
29
|
def upto(end_date)
|
26
30
|
find_occurrences { |roc| roc > end_date }
|
27
31
|
end
|
@@ -74,4 +78,4 @@ module IceCube
|
|
74
78
|
|
75
79
|
end
|
76
80
|
|
77
|
-
end
|
81
|
+
end
|
data/lib/ice_cube/schedule.rb
CHANGED
@@ -2,14 +2,16 @@ module IceCube
|
|
2
2
|
|
3
3
|
class Schedule
|
4
4
|
|
5
|
-
attr_reader :rdates, :exdates
|
5
|
+
attr_reader :rdates, :exdates, :start_date, :duration
|
6
6
|
|
7
|
-
def initialize(start_date)
|
7
|
+
def initialize(start_date, options = {})
|
8
8
|
@rrule_occurrence_heads = []
|
9
9
|
@exrule_occurrence_heads = []
|
10
10
|
@rdates = []
|
11
11
|
@exdates = []
|
12
12
|
@start_date = start_date
|
13
|
+
raise ArgumentError.new('Duration cannot be negative') if options[:duration] && options[:duration] < 0
|
14
|
+
@duration = options[:duration]
|
13
15
|
end
|
14
16
|
|
15
17
|
# Convert the schedule to a hash, reverse of Schedule.from_hash
|
@@ -20,6 +22,7 @@ module IceCube
|
|
20
22
|
hash[:exrules] = @exrule_occurrence_heads.map { |ex| ex.rule.to_hash }
|
21
23
|
hash[:rdates] = @rdates
|
22
24
|
hash[:exdates] = @exdates
|
25
|
+
hash[:duration] = @duration
|
23
26
|
hash
|
24
27
|
end
|
25
28
|
|
@@ -34,7 +37,10 @@ module IceCube
|
|
34
37
|
|
35
38
|
# Create a schedule from a hash created by instance.to_hash
|
36
39
|
def self.from_hash(hash)
|
37
|
-
|
40
|
+
options = {}
|
41
|
+
options[:duration] = hash[:duration] if hash.has_key?(:duration)
|
42
|
+
|
43
|
+
schedule = Schedule.new(hash[:start_date], options)
|
38
44
|
hash[:rrules].each { |rr| schedule.add_recurrence_rule Rule.from_hash(rr) }
|
39
45
|
hash[:exrules].each { |ex| schedule.add_exception_rule Rule.from_hash(ex) }
|
40
46
|
hash[:rdates].each { |rd| schedule.add_recurrence_date rd }
|
@@ -73,7 +79,14 @@ module IceCube
|
|
73
79
|
end
|
74
80
|
representation
|
75
81
|
end
|
76
|
-
|
82
|
+
|
83
|
+
def occurring_at?(time)
|
84
|
+
return false if @exdates.include?(time)
|
85
|
+
return true if @rdates.include?(time)
|
86
|
+
return false if any_occurring_at?(@exrule_occurrence_heads, time)
|
87
|
+
any_occurring_at?(@rrule_occurrence_heads, time)
|
88
|
+
end
|
89
|
+
|
77
90
|
# Determine whether a given time adheres to the ruleset of this schedule.
|
78
91
|
def occurs_at?(date)
|
79
92
|
dates = occurrences(date)
|
@@ -134,9 +147,7 @@ module IceCube
|
|
134
147
|
# Add an individual date exception to this schedule
|
135
148
|
def add_exception_date(date)
|
136
149
|
@exdates << date unless date.nil?
|
137
|
-
end
|
138
|
-
|
139
|
-
attr_reader :rdates, :exdates, :start_date
|
150
|
+
end
|
140
151
|
|
141
152
|
def occurrences_between(begin_time, end_time)
|
142
153
|
exclude_dates, include_dates = Set.new(@exdates), SortedSet.new(@rdates)
|
@@ -152,7 +163,19 @@ module IceCube
|
|
152
163
|
end
|
153
164
|
|
154
165
|
private
|
155
|
-
|
166
|
+
|
167
|
+
# tell if, from a list of rule_occurrence heads, a certain time is occurring
|
168
|
+
def any_occurring_at?(what, time)
|
169
|
+
return false if @start_time && itime < @start_time
|
170
|
+
what.any? do |occurrence_head|
|
171
|
+
# time is less than now and duration is less than that distance
|
172
|
+
possibilities = occurrence_head.between(@start_date, time)
|
173
|
+
possibilities.any? do |possibility|
|
174
|
+
possibility + (@duration || 0) >= time
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
156
179
|
# Find all occurrences (following rules and exceptions) from the schedule's start date to end_date.
|
157
180
|
# Use custom methods to say when to end
|
158
181
|
def find_occurrences
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 9
|
9
|
+
version: 0.3.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Crepezzi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-01 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|