periodoxical 0.7.2 → 0.7.3
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/periodoxical/version.rb +1 -1
- data/lib/periodoxical.rb +25 -30
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63ed27b7ac9376b1cd35d505dbcf13c6637e47a8bee5983aa8697a389c2423ee
|
|
4
|
+
data.tar.gz: df71967f5be8771b0bda25c4b6352f922a82bac39a546f2f66e04247a41ea3cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce019309287e5c8d065e77ce9cdc31348c12d867ba9140a43cfb2da2a086a647dcfd0ef0e1a801c11b41f3794fb0b056d695a7f079ad87e5e77e75bae1646bc2
|
|
7
|
+
data.tar.gz: f8ae7b9cdc4e395618665f5b625624418bdc8d343fdc4e4dccd7aa8af9672671d2d02230d344193ac016ab1ada3468f3e9089b7fcc3b41a110f974d04c5f1486
|
data/Gemfile.lock
CHANGED
data/lib/periodoxical/version.rb
CHANGED
data/lib/periodoxical.rb
CHANGED
|
@@ -87,7 +87,11 @@ module Periodoxical
|
|
|
87
87
|
# {
|
|
88
88
|
# start: #<DateTime>,
|
|
89
89
|
# end: #<DateTime>,
|
|
90
|
-
# }
|
|
90
|
+
# },
|
|
91
|
+
# {
|
|
92
|
+
# start: #<DateTime>,
|
|
93
|
+
# end: #<DateTime>,
|
|
94
|
+
# },
|
|
91
95
|
# ]
|
|
92
96
|
def generate
|
|
93
97
|
initialize_looping_variables!
|
|
@@ -146,12 +150,8 @@ module Periodoxical
|
|
|
146
150
|
end
|
|
147
151
|
end
|
|
148
152
|
|
|
149
|
-
if @
|
|
150
|
-
|
|
151
|
-
overlapping_days = @days_of_week & @nth_day_of_week_in_month.keys.map(&:to_s)
|
|
152
|
-
unless overlapping_days.empty?
|
|
153
|
-
raise "#{overlapping_days} is specified in both `days_of_week` and also `nth_day_of_week_in_month`, which leads to ambiguity. Pleasee look at the README for examples."
|
|
154
|
-
end
|
|
153
|
+
if @nth_day_of_week_in_month && (@days_of_week || @day_of_week_time_blocks)
|
|
154
|
+
raise "nth_day_of_week_in_month parameter cannot be used in combination with `days_of_week` or `day_of_week_time_blocks`. Please look at the README for examples."
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
if @day_of_week_time_blocks
|
|
@@ -228,6 +228,7 @@ module Periodoxical
|
|
|
228
228
|
def initialize_looping_variables!
|
|
229
229
|
@output = []
|
|
230
230
|
@current_date = @start_date
|
|
231
|
+
@current_day_of_week = day_of_week_long_to_short(@current_date.strftime("%A"))
|
|
231
232
|
@current_count = 0
|
|
232
233
|
@keep_generating = true
|
|
233
234
|
end
|
|
@@ -255,10 +256,19 @@ module Periodoxical
|
|
|
255
256
|
|
|
256
257
|
def advance_current_date_and_check_if_reached_end_date
|
|
257
258
|
@current_date = @current_date + 1
|
|
259
|
+
@current_day_of_week = day_of_week_long_to_short(@current_date.strftime("%A"))
|
|
258
260
|
|
|
259
261
|
if @end_date && (@current_date > @end_date)
|
|
260
262
|
@keep_generating = false
|
|
261
263
|
end
|
|
264
|
+
|
|
265
|
+
# kill switch to stop infinite loop when `limit` is used but
|
|
266
|
+
# there is bug, or poorly specified rules. If @current_date goes into
|
|
267
|
+
# 1000 years in the future, but still no dates have been generated yet, this is
|
|
268
|
+
# most likely an infinite loop situation, and needs to be killed.
|
|
269
|
+
if @limit && ((@current_date - @start_date).to_i > 365000) && @output.empty?
|
|
270
|
+
raise "No end condition detected, causing infinite loop. Please check rules/conditions or raise github issue for potential bug fixed"
|
|
271
|
+
end
|
|
262
272
|
end
|
|
263
273
|
|
|
264
274
|
# @return [Boolean]
|
|
@@ -286,17 +296,14 @@ module Periodoxical
|
|
|
286
296
|
return false unless @days_of_month.include?(@current_date.day)
|
|
287
297
|
end
|
|
288
298
|
|
|
289
|
-
# The following conditions depend on the day-of-week of current_date.
|
|
290
|
-
day_of_week = day_of_week_long_to_short(@current_date.strftime("%A"))
|
|
291
|
-
|
|
292
299
|
# If days of week are specified, but current_date does not satisfy it,
|
|
293
300
|
# return false
|
|
294
301
|
if @days_of_week
|
|
295
|
-
return false unless @days_of_week.include?(
|
|
302
|
+
return false unless @days_of_week.include?(@current_day_of_week)
|
|
296
303
|
end
|
|
297
304
|
|
|
298
305
|
if @day_of_week_time_blocks
|
|
299
|
-
dowtb = @day_of_week_time_blocks[
|
|
306
|
+
dowtb = @day_of_week_time_blocks[@current_day_of_week.to_sym]
|
|
300
307
|
return false if dowtb.nil?
|
|
301
308
|
return false if dowtb.empty?
|
|
302
309
|
end
|
|
@@ -304,30 +311,19 @@ module Periodoxical
|
|
|
304
311
|
if @nth_day_of_week_in_month
|
|
305
312
|
# If the day of week is specified in nth_day_of_week_in_month,
|
|
306
313
|
# we need to investigate it whether or not to exclude it.
|
|
307
|
-
if @nth_day_of_week_in_month[
|
|
314
|
+
if @nth_day_of_week_in_month[@current_day_of_week.to_sym]
|
|
308
315
|
n_occurence_of_day_of_week_in_month = ((@current_date.day - 1) / 7) + 1
|
|
309
316
|
# -1 is a special case and requires extra-math
|
|
310
|
-
if @nth_day_of_week_in_month[
|
|
317
|
+
if @nth_day_of_week_in_month[@current_day_of_week.to_sym].include?(-1)
|
|
311
318
|
# We basically want to convert the -1 into its 'positive-equivalent` in this month, and compare it with that.
|
|
312
319
|
# For example, in June 2024, the Last Friday is also the 4th Friday. So in that case, we convert the -1 into a 4.
|
|
313
|
-
positivized_indices = @nth_day_of_week_in_month[
|
|
320
|
+
positivized_indices = @nth_day_of_week_in_month[@current_day_of_week.to_sym].map { |indx| positivize_index(indx, @current_day_of_week) }
|
|
314
321
|
return positivized_indices.include?(n_occurence_of_day_of_week_in_month)
|
|
315
322
|
else
|
|
316
|
-
return @nth_day_of_week_in_month[
|
|
323
|
+
return @nth_day_of_week_in_month[@current_day_of_week.to_sym].include?(n_occurence_of_day_of_week_in_month)
|
|
317
324
|
end
|
|
318
325
|
else
|
|
319
|
-
|
|
320
|
-
# it could have been specified in either `days_of_week` or `day_of_week_time_blocks and we unfortunately need to re-check those here. I cant think of a way to further DRY-it up.
|
|
321
|
-
return false unless @days_of_week && @day_of_week_time_blocks
|
|
322
|
-
if @day_of_week
|
|
323
|
-
return false unless @days_of_week.include?(day_of_week)
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
if @day_of_week_time_blocks
|
|
327
|
-
dowtb = @day_of_week_time_blocks[day_of_week.to_sym]
|
|
328
|
-
return false if dowtb.nil?
|
|
329
|
-
return false if dowtb.empty?
|
|
330
|
-
end
|
|
326
|
+
return false
|
|
331
327
|
end
|
|
332
328
|
end
|
|
333
329
|
|
|
@@ -337,8 +333,7 @@ module Periodoxical
|
|
|
337
333
|
|
|
338
334
|
def add_time_blocks_from_current_date!
|
|
339
335
|
if @day_of_week_time_blocks
|
|
340
|
-
|
|
341
|
-
time_blocks = @day_of_week_time_blocks[day_of_week.to_sym]
|
|
336
|
+
time_blocks = @day_of_week_time_blocks[@current_day_of_week.to_sym]
|
|
342
337
|
catch :done do
|
|
343
338
|
time_blocks.each do |tb|
|
|
344
339
|
append_to_output_and_check_limit(tb)
|