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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01bdfec5ba5930f743cc1c4197e0964631c8dde5be1bb14c79082fe363bf72e1
4
- data.tar.gz: 6aaaf40f368acbdd78632455889298e6eb6ced8c0ee80f4ed9e96387e7d05536
3
+ metadata.gz: 63ed27b7ac9376b1cd35d505dbcf13c6637e47a8bee5983aa8697a389c2423ee
4
+ data.tar.gz: df71967f5be8771b0bda25c4b6352f922a82bac39a546f2f66e04247a41ea3cb
5
5
  SHA512:
6
- metadata.gz: dc697912db1f3a5439ffd3cdf3371c4be7f4475bb2bbae1f01c2ac42887d6041c45763e1977eabf8f68e5f6ee7c7c0d728e80153796acd419d9741a7a3126d5f
7
- data.tar.gz: 7a0c713a31ccca86c48b08bdcf1908056475a589c7adc0b93ed94dd13af0ebd35fe58151340fe2e88ff3da13d653673064c9c1d3500e9dbe61845528ecdbb207
6
+ metadata.gz: ce019309287e5c8d065e77ce9cdc31348c12d867ba9140a43cfb2da2a086a647dcfd0ef0e1a801c11b41f3794fb0b056d695a7f079ad87e5e77e75bae1646bc2
7
+ data.tar.gz: f8ae7b9cdc4e395618665f5b625624418bdc8d343fdc4e4dccd7aa8af9672671d2d02230d344193ac016ab1ada3468f3e9089b7fcc3b41a110f974d04c5f1486
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- periodoxical (0.6.2)
4
+ periodoxical (0.7.3)
5
5
  tzinfo (~> 2.0, >= 2.0.0)
6
6
  week_of_month (= 1.2.6)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Periodoxical
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
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 @days_of_week && @nth_day_of_week_in_month
150
- # If both `days_of_week` and `nth_day_of_week_in_month` are provided for the same days-of-the-week, then it is ambiguous. (ie. I want this timeslot for every Monday, but also only for the first Mondays, well which one is it?)
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?(day_of_week)
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[day_of_week.to_sym]
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[day_of_week.to_sym]
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[day_of_week.to_sym].include?(-1)
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[day_of_week.to_sym].map { |indx| positivize_index(indx, day_of_week) }
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[day_of_week.to_sym].include?(n_occurence_of_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
- # if day-of-week was not specified in nth_day_of_week_in_month,
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
- day_of_week = day_of_week_long_to_short(@current_date.strftime("%A"))
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periodoxical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Li