active-icalendar-events 0.0.1 → 0.1.2

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 +28 -26
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dd12f4342f70824ee8f51ec64c712bb2277948f6e12a077cba2f6b2768c2273
4
- data.tar.gz: af303b6d8d5fa6148528c404a7142c7e5627cf2a76f1402714a8166952b44f1b
3
+ metadata.gz: 981c99140882554d70998f2b1225ce89cb47b80fb7471172c62c215204aecdb5
4
+ data.tar.gz: 5d58a68cb6195024aedb6a0d461c8c03a98a1f88ad5d4c0f0250e4fe08e5d077
5
5
  SHA512:
6
- metadata.gz: 38d5c9328f3c6c3817f2f2d47fd47de1143a4e472498fdcc15349d17977f2016ce121e2b1198db4987f294bd7ebc25995f18ce9fd8144606fde7a58565d63e6f
7
- data.tar.gz: 6b4effda0225339f70f23faab8df05da8933fbd379c81cf46556e814e4fe58375513c91a4c365fc6d1143c83eb57b40e448322e8930f18fc37a6a0f61a1d8fb5
6
+ metadata.gz: 426bb70b73ab75023013c15040498a1fc69605c5c39f08d06a83457e8e29467074064c7058083dd7223d4afad2be5a3d5c281d8a289b79d36560eff124b57ad4
7
+ data.tar.gz: be2600c740997701ffeab23b6eb51e844cefe31912f8c7baa9b383501a4505e50381e52c0fa844be76aad25ca2591403770999809ff0e7d0f88974f15b435083
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler'
4
- Bundler.require
5
-
6
3
  require 'active_support'
7
4
  require 'active_support/core_ext'
8
5
  require 'date'
@@ -90,15 +87,27 @@ module ActiveIcalendarEvents
90
87
  # Remove 'nil' if it has been put in the set
91
88
  active_events.delete nil
92
89
 
93
- active_events
90
+ active_events.to_a
94
91
  end
95
92
 
96
93
  def format_icalendar_data(icalendar_data)
97
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
+
98
107
  {
99
- name: e.summary.downcase,
100
- event_start: e.dtstart,
101
- event_end: e.dtend,
108
+ name: e.summary,
109
+ event_start: event_start,
110
+ event_end: event_end,
102
111
  recurrence_rule: e.rrule,
103
112
  recurrence_dates: e.rdate,
104
113
  excluding_dates: e.exdate,
@@ -141,9 +150,8 @@ module ActiveIcalendarEvents
141
150
  !overridden_dates.include?(event_start_considered)
142
151
  end
143
152
 
144
- if !excluding_dates.include?(event_start_considered)
145
- considered_count += 1
146
- end
153
+ # We consider both active dates and excluded dates for the recurrence count
154
+ considered_count += 1
147
155
 
148
156
  event_start_considered = event_start_considered + interval.days
149
157
  event_end_considered = event_end_considered + interval.days
@@ -177,15 +185,13 @@ module ActiveIcalendarEvents
177
185
  !overridden_dates.include?(event_start_considered)
178
186
  end
179
187
 
180
- if !excluding_dates.include?(event_start_considered)
181
- considered_count += 1
182
- end
188
+ # We consider both active dates and excluded dates for the recurrence count
189
+ considered_count += 1
183
190
  else
184
191
  week_event_start_considered =
185
192
  event_start_considered.monday? ? event_start_considered :
186
193
  event_start_considered.prev_occurring(:monday)
187
- week_event_end_considered =
188
- (week_event_start_considered.to_time + (event_end.to_time - event_start.to_time)).to_datetime
194
+ week_event_end_considered = week_event_start_considered + (event_end.to_time - event_start.to_time).seconds
189
195
 
190
196
  (1..7).each { |_|
191
197
  if week_event_start_considered >= event_start
@@ -203,9 +209,8 @@ module ActiveIcalendarEvents
203
209
  !overridden_dates.include?(week_event_start_considered)
204
210
  end
205
211
 
206
- if !excluding_dates.include?(week_event_start_considered)
207
- considered_count += 1
208
- end
212
+ # We consider both active dates and excluded dates for the recurrence count
213
+ considered_count += 1
209
214
  end
210
215
  end
211
216
 
@@ -288,9 +293,8 @@ module ActiveIcalendarEvents
288
293
  !overridden_dates.include?(event_start_considered)
289
294
  end
290
295
 
291
- if !excluding_dates.include?(event_start_considered)
292
- considered_count += 1
293
- end
296
+ # We consider both active dates and excluded dates for the recurrence count
297
+ considered_count += 1
294
298
 
295
299
  if by_day.nil? || by_day.empty?
296
300
  event_start_considered = event_start_considered + interval.month
@@ -299,8 +303,7 @@ module ActiveIcalendarEvents
299
303
  event_start_considered =
300
304
  get_nth_day_in_month(event_start_considered.beginning_of_month + interval.month,
301
305
  by_day.first)
302
- event_end_considered =
303
- (event_start_considered.to_time + (event_end.to_time - event_start.to_time)).to_datetime
306
+ event_end_considered = event_start_considered + (event_end.to_time - event_start.to_time).seconds
304
307
  end
305
308
  end
306
309
 
@@ -327,9 +330,8 @@ module ActiveIcalendarEvents
327
330
  !overridden_dates.include?(event_start_considered)
328
331
  end
329
332
 
330
- if !excluding_dates.include?(event_start_considered)
331
- considered_count += 1
332
- end
333
+ # We consider both active dates and excluded dates for the recurrence count
334
+ considered_count += 1
333
335
 
334
336
  event_start_considered = event_start_considered + interval.years
335
337
  event_end_considered = event_end_considered + interval.years
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.1
4
+ version: 0.1.2
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