ice_cube 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ module IceCube
6
6
 
7
7
  alias :end_date :end_time
8
8
  alias :start_time :start_date
9
-
9
+
10
10
  def initialize(start_date, options = {})
11
11
  @rrule_occurrence_heads = []
12
12
  @exrule_occurrence_heads = []
@@ -43,11 +43,12 @@ module IceCube
43
43
  end
44
44
 
45
45
  # Create a schedule from a hash created by instance.to_hash
46
- def self.from_hash(hash)
46
+ def self.from_hash(hash, hash_options = {})
47
47
  options = {}
48
48
  options[:duration] = hash[:duration] if hash.has_key?(:duration)
49
49
  options[:end_time] = TimeUtil.deserialize_time(hash[:end_time]) if hash.has_key?(:end_time)
50
- schedule = Schedule.new(TimeUtil.deserialize_time(hash[:start_date]), options)
50
+ start_date = hash_options[:start_date_override] || TimeUtil.deserialize_time(hash[:start_date])
51
+ schedule = Schedule.new(start_date, options)
51
52
  hash[:rrules].each { |rr| schedule.add_recurrence_rule Rule.from_hash(rr) }
52
53
  hash[:exrules].each { |ex| schedule.add_exception_rule Rule.from_hash(ex) }
53
54
  hash[:rdates].each { |rd| schedule.add_recurrence_date TimeUtil.deserialize_time(rd) }
@@ -56,14 +57,14 @@ module IceCube
56
57
  end
57
58
 
58
59
  # Create a schedule from a yaml string created by instance.to_yaml
59
- def self.from_yaml(str)
60
- from_hash(YAML::load(str))
60
+ def self.from_yaml(str, hash_options = {})
61
+ from_hash(YAML::load(str), hash_options)
61
62
  end
62
63
 
63
64
  TIME_FORMAT = '%B %e, %Y'
64
65
  SEPARATOR = ' / '
65
66
  NEWLINE = "\n"
66
-
67
+
67
68
  # use with caution
68
69
  # incomplete and not entirely tested - no time representation in dates
69
70
  # there's a lot that can happen here
@@ -87,9 +88,9 @@ module IceCube
87
88
  representation_pieces.concat @rrule_occurrence_heads.map { |r| "RRULE:#{r.rule.to_ical}" } if @rrule_occurrence_heads
88
89
  representation_pieces.concat @exrule_occurrence_heads.map { |r| "EXRULE:#{r.rule.to_ical}" } if @exrule_occurrence_heads
89
90
  representation_pieces << "DTEND#{TimeUtil.ical_format(@end_time)}" if @end_time
90
- representation_pieces.join(NEWLINE)
91
+ representation_pieces.join(NEWLINE)
91
92
  end
92
-
93
+
93
94
  def occurring_at?(time)
94
95
  return false if @exdates.include?(time)
95
96
  return true if @rdates.include?(time)
@@ -103,7 +104,7 @@ module IceCube
103
104
  dates = occurrences(date)
104
105
  dates.last == date
105
106
  end
106
-
107
+
107
108
  # Determine whether a given date appears in the times returned by the schedule
108
109
  def occurs_on?(date)
109
110
  if defined?(ActiveSupport::TimeWithZone) && @start_date.is_a?(ActiveSupport::TimeWithZone)
@@ -113,14 +114,14 @@ module IceCube
113
114
  time_format = @start_date.utc? ? :utc : :local
114
115
  self.occurrences_between(Time.send(time_format, date.year, date.month, date.day, 0, 0, 0), Time.send(time_format, date.year, date.month, date.day, 23, 59, 59)).any?
115
116
  end
116
-
117
- # Return all possible occurrences
117
+
118
+ # Return all possible occurrences
118
119
  # In order to make this call, all rules in the schedule must have
119
120
  # either an until date or an occurrence count
120
121
  def all_occurrences
121
122
  find_occurrences { |head| head.all_occurrences }
122
123
  end
123
-
124
+
124
125
  # Find all occurrences until a certain date
125
126
  def occurrences(end_date)
126
127
  end_date = @end_time if @end_time && @end_time < end_date
@@ -132,7 +133,7 @@ module IceCube
132
133
  raise ArgumentError.new('Schedule must have an end_time to use remaining_occurrences') unless @end_time
133
134
  occurrences_between(from, @end_time)
134
135
  end
135
-
136
+
136
137
  # Find next scheduled occurrence
137
138
  def next_occurrence(from = Time.now)
138
139
  next_occurrences(1, from).first
@@ -168,7 +169,7 @@ module IceCube
168
169
  @exrule_occurrence_heads << RuleOccurrence.new(rule, @start_date, @end_time)
169
170
  end
170
171
 
171
- def exrules
172
+ def exrules
172
173
  @exrule_occurrence_heads.map { |h| h.rule }
173
174
  end
174
175
 
@@ -180,7 +181,7 @@ module IceCube
180
181
  # Add an individual date exception to this schedule
181
182
  def add_exception_date(date)
182
183
  @exdates << date unless date.nil?
183
- end
184
+ end
184
185
 
185
186
  def occurrences_between(begin_time, end_time)
186
187
  # adjust to the propert end date
@@ -203,16 +204,16 @@ module IceCube
203
204
  alias exdate add_exception_date
204
205
  alias exrule add_exception_rule
205
206
 
206
-
207
+
207
208
  private
208
-
209
+
209
210
  # We know that start_date is a time with zone - so check referencing
210
211
  # The date in that time zone
211
212
  def active_support_occurs_on?(date)
212
213
  time = Time.zone.parse(date.to_s) # date.to_time.in_time_zone(@start_date.time_zone)
213
214
  occurrences_between(time.beginning_of_day, time.end_of_day).any?
214
215
  end
215
-
216
+
216
217
  # tell if, from a list of rule_occurrence heads, a certain time is occurring
217
218
  def any_occurring_at?(what, time)
218
219
  return false if @start_time && time < @start_time
@@ -224,7 +225,7 @@ module IceCube
224
225
  end
225
226
  end
226
227
  end
227
-
228
+
228
229
  # Find all occurrences (following rules and exceptions) from the schedule's start date to end_date.
229
230
  # Use custom methods to say when to end
230
231
  def find_occurrences
@@ -241,7 +242,7 @@ module IceCube
241
242
  include_dates.reject! { |date| exclude_dates.include?(date) }
242
243
  include_dates.to_a
243
244
  end
244
-
245
+
245
246
  end
246
247
 
247
248
  end
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = '0.6.4'
3
+ VERSION = '0.6.5'
4
4
 
5
5
  end
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 5
10
+ version: 0.6.5
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-11-16 00:00:00 -05:00
18
+ date: 2011-01-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency