periodoxical 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ace9209a6c531a382b264e87513dc6e5075499fc90f1eba313404368d96e58ba
4
- data.tar.gz: e1771a96128f204df520f39bfcb54d3a294c130da07d0c9f971b98908fe985ce
3
+ metadata.gz: 9a17e3bd272fdd537b16689e871aa834c6388202d36d5ed5bf420150c0ff62bd
4
+ data.tar.gz: 8c08b584338f8d2e14cb8c0c8ce1ec4171d5fa4c946328911b25302aa621e92e
5
5
  SHA512:
6
- metadata.gz: aaaf84f0c0af53ad1df2f595298a8327fc67574b7a35c08a27a921f0719ef6eea0990a7ee28423755f3baa0abe78d31e4bad7bcd42f82d1c9ebe6607b0fe0574
7
- data.tar.gz: 8eed0bfd9236bb43084c0427a50ac6ce6b793411d30adffd1d12b303ae57d0cf8d5dc0281b1c654aa15584a436066dea7f1a39a5283bdc7ef398df9dde56ec5c
6
+ metadata.gz: 76df9351805289b310b079dd0a44587630db263101a18777ffa4612dacd5e846313fc56b8836ffa42fe7126926456d11273c218187dda0542d5b76c65a6a0451
7
+ data.tar.gz: afed95be8919055c47c5b118b6e01f944b03e16fc2c87046157ece131d35d0078c1dc5cbad804140afb9cdc975283c9d464536a4b65d7549181b5e0781afb628
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- periodoxical (2.2.0)
4
+ periodoxical (2.2.1)
5
5
  tzinfo (~> 2.0, >= 2.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -240,7 +240,8 @@ Periodoxical.generate(
240
240
  ]
241
241
  ```
242
242
 
243
- ### Example 6 - Specify nth day-of-week in month (ie. first Monday of the Month, second Tuesday of the Month, last Friday of Month)
243
+ ### Specify nth day-of-week in month (ie. first Monday of the Month, second Tuesday of the Month, last Friday of Month)
244
+
244
245
  As a Ruby dev, I want to generate timeblocks for **8AM - 9AM** on the **first and second Mondays** and **last Fridays** of every month starting in June 2024. I can do this with the `nth_day_of_week_in_month` param.
245
246
 
246
247
  ```rb
@@ -281,7 +282,7 @@ Periodoxical.generate(
281
282
  ]
282
283
  ```
283
284
 
284
- ### Example 7 - Exclude time blocks using the `exclusion_dates` and `exclusion_times` parameters
285
+ ### Exclude time blocks using the `exclusion_dates` and `exclusion_times` parameters
285
286
  As a Ruby dev, I want to generate timeblocks for **8AM - 9AM** on **Mondays**, except for the **Monday of June 10, 2024**. I can do this using the `exlcusion_dates` parameter.
286
287
 
287
288
  ```rb
@@ -367,7 +368,7 @@ Periodoxical.generate(
367
368
  ]
368
369
  ```
369
370
 
370
- ### Example 8 - Every-other-nth day-of-week rules (ie. every other Tuesday, every 3rd Wednesday, every 10th Friday)
371
+ ### Every-other-nth day-of-week rules (ie. every other Tuesday, every 3rd Wednesday, every 10th Friday)
371
372
 
372
373
  As a Ruby dev, I want to generate timeblocks for **9AM- 10AM** on **every Monday**, but **every other Tuesday**, and **every other 3rd Wednesday**. I can do this using the `days_of_week` parameter with the `every` and `every_other_nth` keys to specify the every-other-nth-rules.
373
374
 
@@ -27,11 +27,14 @@ module Periodoxical
27
27
  tb_2_start = time_block_2[:start]
28
28
  tb_2_end = time_block_2[:end]
29
29
 
30
- # Basicall overlap is when one starts before the other has ended
30
+ # Basically overlap is when one starts before the other has ended
31
31
  return true if tb_1_end > tb_2_start && tb_1_end < tb_2_end
32
32
  # By symmetry
33
33
  return true if tb_2_end > tb_1_start && tb_2_end < tb_1_end
34
34
 
35
+ # Handle the edge case where they start/end at the same time
36
+ return true if tb_1_start == tb_2_start || tb_1_end == tb_2_end
37
+
35
38
  false
36
39
  end
37
40
 
@@ -1,3 +1,3 @@
1
1
  module Periodoxical
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
3
3
  end
data/lib/periodoxical.rb CHANGED
@@ -148,7 +148,7 @@ module Periodoxical
148
148
  # Ex: '9:00AM'
149
149
  # @param [Date] date
150
150
  def time_str_to_object(date, time_str)
151
- time = Time.strptime(time_str, "%I:%M%p")
151
+ time = Time.strptime(time_str, '%I:%M%p')
152
152
  date_time = DateTime.new(
153
153
  date.year,
154
154
  date.month,
@@ -209,19 +209,19 @@ module Periodoxical
209
209
  # }
210
210
  # Generates time block but also checks if we should stop generating
211
211
  def append_to_output_and_check_limit(time_block)
212
- # Check if this particular time is conflicts with any times from `exclusion_times`.
213
- return if overlaps_with_an_excluded_time?(time_block)
214
- return if before_starting_from_or_after_ending_at?(time_block)
215
-
216
212
  strtm = time_str_to_object(@current_date, time_block[:start_time])
217
213
  endtm = time_str_to_object(@current_date, time_block[:end_time])
218
214
 
219
215
  if @duration
220
216
  split_by_duration_and_append(strtm, endtm)
221
217
  else
218
+ # Check if this particular time is conflicts with any times from `exclusion_times`.
219
+ return if before_starting_from_or_after_ending_at?(time_block)
220
+ return if overlaps_with_an_excluded_time?({ start: strtm, end: endtm })
221
+
222
222
  @output << {
223
223
  start: strtm,
224
- end: endtm
224
+ end: endtm
225
225
  }
226
226
  increment_and_check_limit
227
227
  end
@@ -410,19 +410,22 @@ module Periodoxical
410
410
  false
411
411
  end
412
412
 
413
+ # @param [Hash] time_block
414
+ # Ex:
415
+ # {
416
+ # start: #<DateTime>,
417
+ # end: #<DateTime>,
418
+ # }
413
419
  # @return [Boolean]
414
420
  # Whether or not the given `time_block` in the @current_date and
415
421
  # @time_zone overlaps with the times in `exclusion_times`.
416
- def overlaps_with_an_excluded_time?(time_block)
422
+ def overlaps_with_an_excluded_time?(tm_blck)
417
423
  return false unless @exclusion_times
418
424
 
419
425
  @exclusion_times.each do |exclusion_timeblock|
420
426
  return true if overlap?(
421
427
  exclusion_timeblock,
422
- {
423
- start: time_str_to_object(@current_date, time_block[:start_time]),
424
- end: time_str_to_object(@current_date, time_block[:end_time]),
425
- }
428
+ tm_blck
426
429
  )
427
430
  end
428
431
 
@@ -434,13 +437,15 @@ module Periodoxical
434
437
  si = strtm
435
438
  ei = strtm + delta
436
439
  while ei <= endtm
437
- @output << {
438
- start: si,
439
- end: ei
440
- }
440
+ unless overlaps_with_an_excluded_time?({ start: si, end: ei })
441
+ @output << {
442
+ start: si,
443
+ end: ei
444
+ }
445
+ increment_and_check_limit
446
+ end
441
447
  si += delta
442
448
  ei += delta
443
- increment_and_check_limit
444
449
  end
445
450
  end
446
451
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periodoxical
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Li
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo