periodoxical 0.1.2 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +23 -4
- data/lib/periodoxical/version.rb +1 -1
- data/lib/periodoxical.rb +33 -6
- data/periodoxical.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a786f06e166368721d1f0f17d9c702bfc23950f66482f4c2da80fde583d9a5
|
4
|
+
data.tar.gz: 65bae069f30ee999ccc99353d03149db0e3414adbb1257b1c163e2d7cfaa5e01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9f76a36b7a77e326ab999adbda7d59f24f84383f198c260e99b76cfb7c9fe069c10fa3ff46c61c53491e4d6b96f8c23b8378471cd7494cce21e78dbfface58e
|
7
|
+
data.tar.gz: 3ad7d053bb777bf3f3dbf403a787447dc77eeab162d185a6e3de79c21a68d468ac30365aa2ad3d5db65525a2678f78e3f0c5e50e728b22cc521c205445696056
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
periodoxical (0.
|
4
|
+
periodoxical (0.2.2)
|
5
5
|
tzinfo (~> 2.0, >= 2.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -24,7 +24,7 @@ GEM
|
|
24
24
|
pry-stack_explorer (0.6.1)
|
25
25
|
binding_of_caller (~> 1.0)
|
26
26
|
pry (~> 0.13)
|
27
|
-
rake (
|
27
|
+
rake (12.3.3)
|
28
28
|
rspec (3.13.0)
|
29
29
|
rspec-core (~> 3.13.0)
|
30
30
|
rspec-expectations (~> 3.13.0)
|
@@ -49,7 +49,7 @@ DEPENDENCIES
|
|
49
49
|
periodoxical!
|
50
50
|
pry-byebug (~> 3.10)
|
51
51
|
pry-stack_explorer (~> 0.6)
|
52
|
-
rake (~>
|
52
|
+
rake (~> 12.3.3)
|
53
53
|
rspec (~> 3.0)
|
54
54
|
|
55
55
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -23,11 +23,9 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
|
27
|
-
# Generates 9:00AM - 10:30AM and 2:00PM - 2:30PM time blocks
|
28
|
-
# on Mondays, Wednesdays, and Thursdays, between the dates of
|
29
|
-
# May 23, 2024 and June 24, 2024
|
26
|
+
Generates datetimes blocks of 9:00AM - 10:30AM and 2:00PM - 2:30PM, on Mondays, Wednesdays, and Thursdays, between the dates of May 23, 2024 and June 24, 2024
|
30
27
|
|
28
|
+
```rb
|
31
29
|
Periodoxical.generate(
|
32
30
|
time_zone: 'America/Los_Angeles',
|
33
31
|
days_of_week: %w[mon wed thu],
|
@@ -63,6 +61,27 @@ Periodoxical.generate(
|
|
63
61
|
]
|
64
62
|
```
|
65
63
|
|
64
|
+
Generate the next 10 datetime blocks of 3:00PM - 4:30PM, on Sundays, after May 30, 2024
|
65
|
+
|
66
|
+
```rb
|
67
|
+
Periodoxical.generate(
|
68
|
+
time_zone: 'America/Los_Angeles',
|
69
|
+
days_of_week: %w[mon wed thu],
|
70
|
+
time_blocks: [
|
71
|
+
{
|
72
|
+
start_time: '9:00AM',
|
73
|
+
end_time: '10:30AM'
|
74
|
+
},
|
75
|
+
{
|
76
|
+
start_time: '2:00PM',
|
77
|
+
end_time: '2:30PM'
|
78
|
+
}
|
79
|
+
],
|
80
|
+
start_date: Date.parse('2024-05-23'),
|
81
|
+
limit: 10
|
82
|
+
)
|
83
|
+
```
|
84
|
+
|
66
85
|
## Development
|
67
86
|
|
68
87
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/periodoxical/version.rb
CHANGED
data/lib/periodoxical.rb
CHANGED
@@ -17,6 +17,17 @@ module Periodoxical
|
|
17
17
|
# TZInfo::DataTimezone#name from the tzinfo gem (https://github.com/tzinfo/tzinfo)
|
18
18
|
# @param [Date] start_date
|
19
19
|
# @param [Date] end_date
|
20
|
+
# @param [Array<Hash>] time_blocks
|
21
|
+
# Ex: [
|
22
|
+
# {
|
23
|
+
# start_time: '9:00AM',
|
24
|
+
# end_time: '10:30PM'
|
25
|
+
# },
|
26
|
+
# {
|
27
|
+
# start_time: '2:00PM',
|
28
|
+
# end_time: '2:30PM'
|
29
|
+
# }
|
30
|
+
# ]
|
20
31
|
# @param [Array<String>, nil] days_of_week
|
21
32
|
# Days of the week to generate the times for, if nil, then times are generated
|
22
33
|
# for every day.
|
@@ -31,7 +42,7 @@ module Periodoxical
|
|
31
42
|
# fri: { start_time: '7:00PM', end_time: '9:00PM' },
|
32
43
|
# }
|
33
44
|
def initialize(time_zone: 'Etc/UTC', days_of_week: nil,
|
34
|
-
start_date:, end_date
|
45
|
+
start_date:, end_date: nil, time_blocks: nil, day_of_week_hours: nil, limit: nil)
|
35
46
|
@time_zone = TZInfo::Timezone.get(time_zone)
|
36
47
|
@days_of_week = days_of_week
|
37
48
|
@time_blocks = time_blocks
|
@@ -58,21 +69,32 @@ module Periodoxical
|
|
58
69
|
private
|
59
70
|
|
60
71
|
def generate_from_days_of_week_time_blocks
|
61
|
-
|
72
|
+
times_output = []
|
62
73
|
current_date = @start_date
|
63
|
-
|
74
|
+
current_count = 0
|
75
|
+
keep_generating = true
|
76
|
+
while keep_generating
|
64
77
|
day_of_week = day_of_week_long_to_short(current_date.strftime("%A"))
|
65
78
|
if @days_of_week.include?(day_of_week)
|
66
79
|
@time_blocks.each do |tb|
|
67
|
-
|
80
|
+
times_output << {
|
68
81
|
start: time_str_to_object(current_date, tb[:start_time]),
|
69
82
|
end: time_str_to_object(current_date, tb[:end_time])
|
70
83
|
}
|
84
|
+
current_count = current_count + 1
|
85
|
+
if @limit && current_count == @limit
|
86
|
+
keep_generating = false
|
87
|
+
break
|
88
|
+
end
|
71
89
|
end
|
72
90
|
end
|
73
91
|
current_date = current_date + 1
|
92
|
+
|
93
|
+
if @end_date && (current_date > @end_date)
|
94
|
+
keep_generating = false
|
95
|
+
end
|
74
96
|
end
|
75
|
-
|
97
|
+
times_output
|
76
98
|
end
|
77
99
|
|
78
100
|
def validate!
|
@@ -93,7 +115,12 @@ module Periodoxical
|
|
93
115
|
end
|
94
116
|
end
|
95
117
|
|
96
|
-
unless (@days_of_week && @
|
118
|
+
unless (@days_of_week && @time_blocks) || (@day_of_week_hours)
|
119
|
+
raise "Need to provide either `days_of_week` and `time_blocks` or `day_of_week_hours`"
|
120
|
+
end
|
121
|
+
|
122
|
+
unless( @limit || @end_date)
|
123
|
+
raise "Either `limit` or `end_date` must be provided"
|
97
124
|
end
|
98
125
|
end
|
99
126
|
|
data/periodoxical.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_dependency 'tzinfo', '~> 2.0', '>= 2.0.0'
|
38
38
|
|
39
39
|
spec.add_development_dependency "bundler", "~> 2.4"
|
40
|
-
spec.add_development_dependency "rake", "~>
|
40
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
42
42
|
spec.add_development_dependency "pry-byebug", "~> 3.10"
|
43
43
|
spec.add_development_dependency "pry-stack_explorer", "~> 0.6"
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Li
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 12.3.3
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 12.3.3
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|