active-icalendar-events 0.1.0 → 0.1.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active-icalendar-events.rb +62 -30
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66faac211abc46fa695ee95745004e6223cd07be003036c26d7fcbf91c2b0818
4
- data.tar.gz: c526790a49ab6a346eafe16592775e9d04afc5084fa8eae1ba20ca4bc44a1522
3
+ metadata.gz: ee9cc0c47ee4498afaf37e853db464fca142261bbf29aaa17439f66508c2610c
4
+ data.tar.gz: a3e5972072dbb410c1949cc2d53a7e7db741e55d9619ed628cc97c2ed2a3d1bf
5
5
  SHA512:
6
- metadata.gz: b075bbe5774a836656ebb7849d052f26a03ec321a335b181424fedecb4929e32e1f41eb11cb39d56f5922cb3fad2a986eb0fc938f074c34ca1f9b95fecc590a6
7
- data.tar.gz: 5b8fa60c24e61314eee6e8d829ae02988ae9a57940d152de5ded2f6e62d96f6442df7a0c6d7c0a7e567735224668d50909d99121e7389430a8b392152b88884f
6
+ metadata.gz: 4f9dbc20940280b719b5d4770e2e2de94544d5671a4b9aa1b6eceb41a126077d44e8d101eabd599f9885de7112d658000b199d8e305900d730b1f173565e94f8
7
+ data.tar.gz: f269876565330984d37d22c592dbef52102d774c387399698af734136347bb90387bea64a6dd25e6b0f64745a946e48d1efb593576966d31e7ec281d3e17cf34
@@ -92,13 +92,50 @@ module ActiveIcalendarEvents
92
92
 
93
93
  def format_icalendar_data(icalendar_data)
94
94
  icalendar_data.first.events.map { |e|
95
+ event_start = e.dtstart
96
+ if event_start.is_a?(Icalendar::Values::Date)
97
+ timezone ||= ActiveSupport::TimeZone.new(e.parent.timezones.first.tzid.to_s)
98
+ event_start = timezone.local(event_start.year, event_start.month, event_start.day)
99
+ end
100
+
101
+ event_end = e.dtend
102
+ if event_end.is_a?(Icalendar::Values::Date)
103
+ timezone ||= ActiveSupport::TimeZone.new(e.parent.timezones.first.tzid.to_s)
104
+ event_end = timezone.local(event_end.year, event_end.month, event_end.day)
105
+ end
106
+
107
+ excluding_dates = e.exdate.map { |d|
108
+ if d.is_a?(Icalendar::Values::Date)
109
+ timezone ||= ActiveSupport::TimeZone.new(e.parent.timezones.first.tzid.to_s)
110
+ timezone.local(d.year, d.month, d.day)
111
+ else
112
+ d
113
+ end
114
+ }
115
+
116
+ recurrence_dates = e.rdate.map { |d|
117
+ if d.is_a?(Icalendar::Values::Date)
118
+ timezone ||= ActiveSupport::TimeZone.new(e.parent.timezones.first.tzid.to_s)
119
+ timezone.local(d.year, d.month, d.day)
120
+ else
121
+ d
122
+ end
123
+ }
124
+
125
+ e.rrule.each { |rrule|
126
+ if !rrule.until.nil?
127
+ timezone ||= ActiveSupport::TimeZone.new(e.parent.timezones.first.tzid.to_s)
128
+ rrule.until = timezone.parse(rrule.until)
129
+ end
130
+ }
131
+
95
132
  {
96
133
  name: e.summary,
97
- event_start: e.dtstart,
98
- event_end: e.dtend,
134
+ event_start: event_start,
135
+ event_end: event_end,
99
136
  recurrence_rule: e.rrule,
100
- recurrence_dates: e.rdate,
101
- excluding_dates: e.exdate,
137
+ recurrence_dates: recurrence_dates,
138
+ excluding_dates: excluding_dates,
102
139
  recurrence_id: e.recurrence_id,
103
140
  uid: e.uid
104
141
  }
@@ -138,9 +175,8 @@ module ActiveIcalendarEvents
138
175
  !overridden_dates.include?(event_start_considered)
139
176
  end
140
177
 
141
- if !excluding_dates.include?(event_start_considered)
142
- considered_count += 1
143
- end
178
+ # We consider both active dates and excluded dates for the recurrence count
179
+ considered_count += 1
144
180
 
145
181
  event_start_considered = event_start_considered + interval.days
146
182
  event_end_considered = event_end_considered + interval.days
@@ -174,9 +210,8 @@ module ActiveIcalendarEvents
174
210
  !overridden_dates.include?(event_start_considered)
175
211
  end
176
212
 
177
- if !excluding_dates.include?(event_start_considered)
178
- considered_count += 1
179
- end
213
+ # We consider both active dates and excluded dates for the recurrence count
214
+ considered_count += 1
180
215
  else
181
216
  week_event_start_considered =
182
217
  event_start_considered.monday? ? event_start_considered :
@@ -199,9 +234,8 @@ module ActiveIcalendarEvents
199
234
  !overridden_dates.include?(week_event_start_considered)
200
235
  end
201
236
 
202
- if !excluding_dates.include?(week_event_start_considered)
203
- considered_count += 1
204
- end
237
+ # We consider both active dates and excluded dates for the recurrence count
238
+ considered_count += 1
205
239
  end
206
240
  end
207
241
 
@@ -217,6 +251,11 @@ module ActiveIcalendarEvents
217
251
  false
218
252
  end
219
253
 
254
+ # Get the beginning of the month, maintaining the timestamp
255
+ def beginning_of_month(datetime)
256
+ datetime - (datetime.day - 1).days
257
+ end
258
+
220
259
  def get_nth_day_in_month(datetime, day)
221
260
  matches = day.match /^([0-9]+)([A-Z]+)$/
222
261
  if matches.nil?
@@ -244,7 +283,7 @@ module ActiveIcalendarEvents
244
283
  raise RuntimeError, "Unexpected day code used"
245
284
  end
246
285
 
247
- target_day = datetime.beginning_of_month
286
+ target_day = beginning_of_month(datetime)
248
287
 
249
288
  if target_day.strftime("%^a").chop != day_code
250
289
  target_day = target_day.next_occurring(day_label)
@@ -284,16 +323,15 @@ module ActiveIcalendarEvents
284
323
  !overridden_dates.include?(event_start_considered)
285
324
  end
286
325
 
287
- if !excluding_dates.include?(event_start_considered)
288
- considered_count += 1
289
- end
326
+ # We consider both active dates and excluded dates for the recurrence count
327
+ considered_count += 1
290
328
 
291
329
  if by_day.nil? || by_day.empty?
292
330
  event_start_considered = event_start_considered + interval.month
293
331
  event_end_considered = event_end_considered + interval.month
294
332
  else
295
333
  event_start_considered =
296
- get_nth_day_in_month(event_start_considered.beginning_of_month + interval.month,
334
+ get_nth_day_in_month(beginning_of_month(event_start_considered) + interval.month,
297
335
  by_day.first)
298
336
  event_end_considered = event_start_considered + (event_end.to_time - event_start.to_time).seconds
299
337
  end
@@ -322,9 +360,8 @@ module ActiveIcalendarEvents
322
360
  !overridden_dates.include?(event_start_considered)
323
361
  end
324
362
 
325
- if !excluding_dates.include?(event_start_considered)
326
- considered_count += 1
327
- end
363
+ # We consider both active dates and excluded dates for the recurrence count
364
+ considered_count += 1
328
365
 
329
366
  event_start_considered = event_start_considered + interval.years
330
367
  event_end_considered = event_end_considered + interval.years
@@ -355,18 +392,13 @@ module ActiveIcalendarEvents
355
392
  return name if is_event_active?(datetime, recurrence_event_start, recurrence_event_end)
356
393
  }
357
394
 
358
- until_datetime = nil
359
- if !recurrence_rule.until.nil?
360
- until_datetime = DateTime.parse(recurrence_rule.until)
361
- end
362
-
363
395
  case recurrence_rule.frequency
364
396
  when "DAILY"
365
397
  return name if is_daily_event_active_for_datetime?(
366
398
  datetime,
367
399
  event_start,
368
400
  event_end,
369
- until_datetime,
401
+ recurrence_rule.until,
370
402
  recurrence_rule.count,
371
403
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
372
404
  excluding_dates,
@@ -377,7 +409,7 @@ module ActiveIcalendarEvents
377
409
  datetime,
378
410
  event_start,
379
411
  event_end,
380
- until_datetime,
412
+ recurrence_rule.until,
381
413
  recurrence_rule.count,
382
414
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
383
415
  recurrence_rule.by_day,
@@ -389,7 +421,7 @@ module ActiveIcalendarEvents
389
421
  datetime,
390
422
  event_start,
391
423
  event_end,
392
- until_datetime,
424
+ recurrence_rule.until,
393
425
  recurrence_rule.count,
394
426
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
395
427
  recurrence_rule.by_day,
@@ -402,7 +434,7 @@ module ActiveIcalendarEvents
402
434
  datetime,
403
435
  event_start,
404
436
  event_end,
405
- until_datetime,
437
+ recurrence_rule.until,
406
438
  recurrence_rule.count,
407
439
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
408
440
  excluding_dates,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-icalendar-events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Starling