active-icalendar-events 0.0.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active-icalendar-events.rb +59 -34
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b212810d18b04c9d70bdfc4bdf9f23dc98ac30e0342ed7087807210080deaf15
4
- data.tar.gz: 31679287a660305ec7df1cc588c6abbf1a53c90becca8f1154a5388e6731eae7
3
+ metadata.gz: aec07e1857f72267287393b71a8d3cf600a8ad92814ef862c99b8693890e473e
4
+ data.tar.gz: 95720ab414ecd1df386c6f7c1c9f7664313c1efb3437b65d464616c18c9b3a68
5
5
  SHA512:
6
- metadata.gz: eda2bbc9424bf898d1aafe3f3085f11e7bb283a72c6d1b4e29d92d9790db8db3732bbae4058c77b92094d8ce2507a26a04f09ee8c64f4b6986c98a28318e3cbe
7
- data.tar.gz: 6c40b35406af38798b9acd4d5df6caec1b9daa31053571d7837cf7722ed26f77c2c835a8d58848006f5533b9400d3b6cfbeab8b0b4c05e59c359bae6b6d192f9
6
+ metadata.gz: bf9a2bd544578257b52702aaaa71900116cf4a97ecc1b02e35a326d2550806350956fb4dcf17b5dd9e2ca66b8deef33e6a43197db8412a87198ba4f49aaaee76
7
+ data.tar.gz: ca6940f8a84da10a6f2c9477ee525507a105b8691afabc3e113999ab2b3584ddb8a95f918109cc6018d440fee7375c28dbb78242e49820f554bdd4c7b1de63b3
@@ -87,18 +87,55 @@ module ActiveIcalendarEvents
87
87
  # Remove 'nil' if it has been put in the set
88
88
  active_events.delete nil
89
89
 
90
- active_events
90
+ active_events.to_a
91
91
  end
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
- name: e.summary.downcase,
97
- event_start: e.dtstart,
98
- event_end: e.dtend,
133
+ name: e.summary,
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,15 +210,13 @@ 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 :
183
218
  event_start_considered.prev_occurring(:monday)
184
- week_event_end_considered =
185
- (week_event_start_considered.to_time + (event_end.to_time - event_start.to_time)).to_datetime
219
+ week_event_end_considered = week_event_start_considered + (event_end.to_time - event_start.to_time).seconds
186
220
 
187
221
  (1..7).each { |_|
188
222
  if week_event_start_considered >= event_start
@@ -200,9 +234,8 @@ module ActiveIcalendarEvents
200
234
  !overridden_dates.include?(week_event_start_considered)
201
235
  end
202
236
 
203
- if !excluding_dates.include?(week_event_start_considered)
204
- considered_count += 1
205
- end
237
+ # We consider both active dates and excluded dates for the recurrence count
238
+ considered_count += 1
206
239
  end
207
240
  end
208
241
 
@@ -285,9 +318,8 @@ module ActiveIcalendarEvents
285
318
  !overridden_dates.include?(event_start_considered)
286
319
  end
287
320
 
288
- if !excluding_dates.include?(event_start_considered)
289
- considered_count += 1
290
- end
321
+ # We consider both active dates and excluded dates for the recurrence count
322
+ considered_count += 1
291
323
 
292
324
  if by_day.nil? || by_day.empty?
293
325
  event_start_considered = event_start_considered + interval.month
@@ -296,8 +328,7 @@ module ActiveIcalendarEvents
296
328
  event_start_considered =
297
329
  get_nth_day_in_month(event_start_considered.beginning_of_month + interval.month,
298
330
  by_day.first)
299
- event_end_considered =
300
- (event_start_considered.to_time + (event_end.to_time - event_start.to_time)).to_datetime
331
+ event_end_considered = event_start_considered + (event_end.to_time - event_start.to_time).seconds
301
332
  end
302
333
  end
303
334
 
@@ -324,9 +355,8 @@ module ActiveIcalendarEvents
324
355
  !overridden_dates.include?(event_start_considered)
325
356
  end
326
357
 
327
- if !excluding_dates.include?(event_start_considered)
328
- considered_count += 1
329
- end
358
+ # We consider both active dates and excluded dates for the recurrence count
359
+ considered_count += 1
330
360
 
331
361
  event_start_considered = event_start_considered + interval.years
332
362
  event_end_considered = event_end_considered + interval.years
@@ -357,18 +387,13 @@ module ActiveIcalendarEvents
357
387
  return name if is_event_active?(datetime, recurrence_event_start, recurrence_event_end)
358
388
  }
359
389
 
360
- until_datetime = nil
361
- if !recurrence_rule.until.nil?
362
- until_datetime = DateTime.parse(recurrence_rule.until)
363
- end
364
-
365
390
  case recurrence_rule.frequency
366
391
  when "DAILY"
367
392
  return name if is_daily_event_active_for_datetime?(
368
393
  datetime,
369
394
  event_start,
370
395
  event_end,
371
- until_datetime,
396
+ recurrence_rule.until,
372
397
  recurrence_rule.count,
373
398
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
374
399
  excluding_dates,
@@ -379,7 +404,7 @@ module ActiveIcalendarEvents
379
404
  datetime,
380
405
  event_start,
381
406
  event_end,
382
- until_datetime,
407
+ recurrence_rule.until,
383
408
  recurrence_rule.count,
384
409
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
385
410
  recurrence_rule.by_day,
@@ -391,7 +416,7 @@ module ActiveIcalendarEvents
391
416
  datetime,
392
417
  event_start,
393
418
  event_end,
394
- until_datetime,
419
+ recurrence_rule.until,
395
420
  recurrence_rule.count,
396
421
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
397
422
  recurrence_rule.by_day,
@@ -404,7 +429,7 @@ module ActiveIcalendarEvents
404
429
  datetime,
405
430
  event_start,
406
431
  event_end,
407
- until_datetime,
432
+ recurrence_rule.until,
408
433
  recurrence_rule.count,
409
434
  recurrence_rule.interval.nil? ? 1 : recurrence_rule.interval,
410
435
  excluding_dates,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-icalendar-events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Starling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-26 00:00:00.000000000 Z
11
+ date: 2021-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport