periodoxical 1.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -3
- data/README.md +4 -38
- data/lib/periodoxical/helpers.rb +4 -1
- data/lib/periodoxical/version.rb +1 -1
- data/lib/periodoxical.rb +21 -24
- data/periodoxical.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a17e3bd272fdd537b16689e871aa834c6388202d36d5ed5bf420150c0ff62bd
|
4
|
+
data.tar.gz: 8c08b584338f8d2e14cb8c0c8ce1ec4171d5fa4c946328911b25302aa621e92e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76df9351805289b310b079dd0a44587630db263101a18777ffa4612dacd5e846313fc56b8836ffa42fe7126926456d11273c218187dda0542d5b76c65a6a0451
|
7
|
+
data.tar.gz: afed95be8919055c47c5b118b6e01f944b03e16fc2c87046157ece131d35d0078c1dc5cbad804140afb9cdc975283c9d464536a4b65d7549181b5e0781afb628
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
periodoxical (
|
4
|
+
periodoxical (2.2.1)
|
5
5
|
tzinfo (~> 2.0, >= 2.0.0)
|
6
|
-
week_of_month (= 1.2.6)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
@@ -41,7 +40,6 @@ GEM
|
|
41
40
|
rspec-support (3.13.1)
|
42
41
|
tzinfo (2.0.6)
|
43
42
|
concurrent-ruby (~> 1.0)
|
44
|
-
week_of_month (1.2.6)
|
45
43
|
|
46
44
|
PLATFORMS
|
47
45
|
arm64-darwin-22
|
data/README.md
CHANGED
@@ -209,7 +209,7 @@ Periodoxical.generate(
|
|
209
209
|
)
|
210
210
|
```
|
211
211
|
|
212
|
-
### Specifying time blocks using rules for
|
212
|
+
### Specifying time blocks using rules for month(s) and/or day-of-month.
|
213
213
|
|
214
214
|
As a Ruby dev, I want to generate the next 3 timeblocks for **8AM - 9AM** for the **5th** and **10th** day of every month starting from **June**. I can do this using the `days_of_month` parameter.
|
215
215
|
|
@@ -240,42 +240,8 @@ Periodoxical.generate(
|
|
240
240
|
]
|
241
241
|
```
|
242
242
|
|
243
|
-
|
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
|
-
```
|
246
|
-
Periodoxical.generate(
|
247
|
-
time_zone: 'America/Los_Angeles',
|
248
|
-
starting_from: '2024-04-01',
|
249
|
-
limit: 4,
|
250
|
-
weeks_of_month: [1 2],
|
251
|
-
months: [4, 5, 6],
|
252
|
-
days_of_week: %w(mon),
|
253
|
-
time_blocks: [
|
254
|
-
{ start_time: '8:00AM', end_time: '9:00AM' },
|
255
|
-
],
|
256
|
-
)
|
257
|
-
#=>
|
258
|
-
[
|
259
|
-
{
|
260
|
-
start_time: #<DateTime: 2024-04-01T08:00:00-0700>,
|
261
|
-
end_time: #<DateTime: 2024-04-01T09:00:00-0700>,
|
262
|
-
},
|
263
|
-
{
|
264
|
-
start_time: #<DateTime: 2024-04-08T08:00:00-0700>,
|
265
|
-
end_time: #<DateTime: 2024-04-08T09:00:00-0700>,
|
266
|
-
},
|
267
|
-
{
|
268
|
-
start_time: #<DateTime: 2024-05-06T08:00:00-0700>,
|
269
|
-
end_time: #<DateTime: 2024-05-06T09:00:00-0700>,
|
270
|
-
},
|
271
|
-
{
|
272
|
-
start_time: #<DateTime: 2024-06-03T08:00:00-0700>,
|
273
|
-
end_time: #<DateTime: 2024-06-03T09:00:00-0700>,
|
274
|
-
},
|
275
|
-
]
|
276
|
-
```
|
277
|
-
|
278
|
-
### Example 6 - Specify nth day-of-week in month (ie. first Monday of the Month, second Tuesday of the Month, last Friday of Month)
|
279
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.
|
280
246
|
|
281
247
|
```rb
|
@@ -316,7 +282,7 @@ Periodoxical.generate(
|
|
316
282
|
]
|
317
283
|
```
|
318
284
|
|
319
|
-
###
|
285
|
+
### Exclude time blocks using the `exclusion_dates` and `exclusion_times` parameters
|
320
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.
|
321
287
|
|
322
288
|
```rb
|
@@ -402,7 +368,7 @@ Periodoxical.generate(
|
|
402
368
|
]
|
403
369
|
```
|
404
370
|
|
405
|
-
###
|
371
|
+
### Every-other-nth day-of-week rules (ie. every other Tuesday, every 3rd Wednesday, every 10th Friday)
|
406
372
|
|
407
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.
|
408
374
|
|
data/lib/periodoxical/helpers.rb
CHANGED
@@ -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
|
-
#
|
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
|
|
data/lib/periodoxical/version.rb
CHANGED
data/lib/periodoxical.rb
CHANGED
@@ -4,7 +4,6 @@ require "periodoxical/helpers"
|
|
4
4
|
require "date"
|
5
5
|
require "time"
|
6
6
|
require "tzinfo"
|
7
|
-
require "week_of_month"
|
8
7
|
|
9
8
|
module Periodoxical
|
10
9
|
class << self
|
@@ -84,7 +83,6 @@ module Periodoxical
|
|
84
83
|
days_of_week: nil,
|
85
84
|
nth_day_of_week_in_month: nil,
|
86
85
|
days_of_month: nil,
|
87
|
-
weeks_of_month: nil,
|
88
86
|
duration: nil,
|
89
87
|
months: nil
|
90
88
|
)
|
@@ -97,7 +95,6 @@ module Periodoxical
|
|
97
95
|
end
|
98
96
|
@nth_day_of_week_in_month = deep_symbolize_keys(nth_day_of_week_in_month)
|
99
97
|
@days_of_month = days_of_month
|
100
|
-
@weeks_of_month = weeks_of_month
|
101
98
|
@months = months
|
102
99
|
@time_blocks = deep_symbolize_keys(time_blocks)
|
103
100
|
@day_of_week_time_blocks = deep_symbolize_keys(day_of_week_time_blocks)
|
@@ -151,7 +148,7 @@ module Periodoxical
|
|
151
148
|
# Ex: '9:00AM'
|
152
149
|
# @param [Date] date
|
153
150
|
def time_str_to_object(date, time_str)
|
154
|
-
time = Time.strptime(time_str,
|
151
|
+
time = Time.strptime(time_str, '%I:%M%p')
|
155
152
|
date_time = DateTime.new(
|
156
153
|
date.year,
|
157
154
|
date.month,
|
@@ -212,19 +209,19 @@ module Periodoxical
|
|
212
209
|
# }
|
213
210
|
# Generates time block but also checks if we should stop generating
|
214
211
|
def append_to_output_and_check_limit(time_block)
|
215
|
-
# Check if this particular time is conflicts with any times from `exclusion_times`.
|
216
|
-
return if overlaps_with_an_excluded_time?(time_block)
|
217
|
-
return if before_starting_from_or_after_ending_at?(time_block)
|
218
|
-
|
219
212
|
strtm = time_str_to_object(@current_date, time_block[:start_time])
|
220
213
|
endtm = time_str_to_object(@current_date, time_block[:end_time])
|
221
214
|
|
222
215
|
if @duration
|
223
216
|
split_by_duration_and_append(strtm, endtm)
|
224
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
|
+
|
225
222
|
@output << {
|
226
223
|
start: strtm,
|
227
|
-
end: endtm
|
224
|
+
end: endtm
|
228
225
|
}
|
229
226
|
increment_and_check_limit
|
230
227
|
end
|
@@ -267,11 +264,6 @@ module Periodoxical
|
|
267
264
|
return false if @exclusion_dates.include?(@current_date)
|
268
265
|
end
|
269
266
|
|
270
|
-
# If weeks_of_months are specified but not satisified, return false
|
271
|
-
if @weeks_of_month
|
272
|
-
return false unless @weeks_of_month.include?(@current_date.week_of_month)
|
273
|
-
end
|
274
|
-
|
275
267
|
# If months are specified, but current_date does not satisfy months,
|
276
268
|
# return false
|
277
269
|
if @months
|
@@ -418,19 +410,22 @@ module Periodoxical
|
|
418
410
|
false
|
419
411
|
end
|
420
412
|
|
413
|
+
# @param [Hash] time_block
|
414
|
+
# Ex:
|
415
|
+
# {
|
416
|
+
# start: #<DateTime>,
|
417
|
+
# end: #<DateTime>,
|
418
|
+
# }
|
421
419
|
# @return [Boolean]
|
422
420
|
# Whether or not the given `time_block` in the @current_date and
|
423
421
|
# @time_zone overlaps with the times in `exclusion_times`.
|
424
|
-
def overlaps_with_an_excluded_time?(
|
422
|
+
def overlaps_with_an_excluded_time?(tm_blck)
|
425
423
|
return false unless @exclusion_times
|
426
424
|
|
427
425
|
@exclusion_times.each do |exclusion_timeblock|
|
428
426
|
return true if overlap?(
|
429
427
|
exclusion_timeblock,
|
430
|
-
|
431
|
-
start: time_str_to_object(@current_date, time_block[:start_time]),
|
432
|
-
end: time_str_to_object(@current_date, time_block[:end_time]),
|
433
|
-
}
|
428
|
+
tm_blck
|
434
429
|
)
|
435
430
|
end
|
436
431
|
|
@@ -442,13 +437,15 @@ module Periodoxical
|
|
442
437
|
si = strtm
|
443
438
|
ei = strtm + delta
|
444
439
|
while ei <= endtm
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
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
|
449
447
|
si += delta
|
450
448
|
ei += delta
|
451
|
-
increment_and_check_limit
|
452
449
|
end
|
453
450
|
end
|
454
451
|
end
|
data/periodoxical.gemspec
CHANGED
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
|
37
37
|
spec.add_dependency 'tzinfo', '~> 2.0', '>= 2.0.0'
|
38
|
-
spec.add_dependency 'week_of_month', '1.2.6'
|
39
38
|
|
40
39
|
spec.add_development_dependency "bundler", "~> 2.4"
|
41
40
|
spec.add_development_dependency "rake", "~> 12.3.3"
|
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:
|
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
|
11
|
+
date: 2024-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -30,20 +30,6 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 2.0.0
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: week_of_month
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - '='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 1.2.6
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - '='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.2.6
|
47
33
|
- !ruby/object:Gem::Dependency
|
48
34
|
name: bundler
|
49
35
|
requirement: !ruby/object:Gem::Requirement
|