periodoxical 0.4.2 → 0.5.2

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: 95c80ef1e3008c4279f58b029a0790353aae3b346d809390c38961b719c635a9
4
- data.tar.gz: 8531378c87459b8dc1945984da0c12b11238a6895668885751923779df3c1bd3
3
+ metadata.gz: fa1a430d11ca7fdd0cea524011b7164f926f87bad37a49c4848bdbca934bdc79
4
+ data.tar.gz: fea338a55f3b095b4ac6c1ff57f235e8490a9b6683ae48b9a573b0b1afba22f0
5
5
  SHA512:
6
- metadata.gz: 899994a59c14f4c6dcf3e8534e7812496ebf53a8b902506e2efebd695d193abf9a93844ccd42389dc2be35c22f2ca829a0d19e3d1de44f7fa4b28d0f5baf3e79
7
- data.tar.gz: fdc25739ed5cf90e3aa1a71617c927382ed56dcbf7b2b292844bc3c3bbd5f4688fc9bf6c03ccddc58e8e930435835833d9fd092c30a31cdef0a243d19c1ad19d
6
+ metadata.gz: 74ec882770d5567ad292ad26c020777d9075cbb0bf77259f37fa0713ab239772dea1dd52fadb2d415ceb8820a10cbc2572ee4847ac181ae208d81d6d759b0517
7
+ data.tar.gz: e2a7c7b00eec3522ce4d2bd15a999a7f86de8826245c464f0e0844b3f7cd42d7eb942d80e7cad2ecbc48d66399f4962fd9f7be7d8a9d4a025e51d79b477112e2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- periodoxical (0.4.2)
4
+ periodoxical (0.5.2)
5
5
  tzinfo (~> 2.0, >= 2.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -148,6 +148,43 @@ Periodoxical.generate(
148
148
  )
149
149
  ```
150
150
 
151
+ #### Example 4 - Exclude time blocks using the `exclusion_dates` parameter
152
+ As a Ruby dev, I want to generate slots for 8AM - 9AM on Mondays, except for the Monday of June 10, 2024.
153
+
154
+ ```rb
155
+ Periodoxical.generate(
156
+ time_zone: 'America/Los_Angeles',
157
+ start_date: '2024-06-3',
158
+ limit: 4,
159
+ exclusion_dates: %w(2024-06-10),
160
+ day_of_week_time_blocks: {
161
+ mon: [
162
+ { start_time: '8:00AM', end_time: '9:00AM' },
163
+ ],
164
+ }
165
+ )
166
+ # Returns all Monday 8AM - 9AM blocks except for the june on June 10, 2024
167
+ # =>
168
+ [
169
+ {
170
+ start: <#DateTime: 2024-06-03T08:00:00-0700>,
171
+ end: <#DateTime: 2024-06-03T09:00:00-0700>,
172
+ }
173
+ {
174
+ start: <#DateTime: 2024-06-17T08:00:00-0700>,
175
+ end: <#DateTime: 2024-06-17T09:00:00-0700>,
176
+ }
177
+ {
178
+ start: <#DateTime: 2024-06-24T08:00:00-0700>,
179
+ end: <#DateTime: 2024-06-24T09:00:00-0700>,
180
+ }
181
+ {
182
+ start: <#DateTime: 2024-07-01T08:00:00-0700>,
183
+ end: <#DateTime: 2024-07-01T09:00:00-0700>,
184
+ }
185
+ ]
186
+ ```
187
+
151
188
  ## Development
152
189
 
153
190
  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.
@@ -1,3 +1,3 @@
1
1
  module Periodoxical
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.2"
3
3
  end
data/lib/periodoxical.rb CHANGED
@@ -34,6 +34,9 @@ module Periodoxical
34
34
  # Ex: %w(mon tue wed sat)
35
35
  # @param [Integer] limit
36
36
  # How many date times to generate. To be used when `end_date` is nil.
37
+ # @param [Aray<String>] exclusion_dates
38
+ # Dates to be excluded when generating the time blocks
39
+ # Ex: ['2024-06-10', '2024-06-14']
37
40
  # @param [Hash<Hash>] day_of_week_time_blocks
38
41
  # To be used when hours are different between days of the week
39
42
  # Ex: {
@@ -42,7 +45,7 @@ module Periodoxical
42
45
  # fri: { start_time: '7:00PM', end_time: '9:00PM' },
43
46
  # }
44
47
  def initialize(time_zone: 'Etc/UTC', days_of_week: nil,
45
- start_date:, end_date: nil, time_blocks: nil, day_of_week_time_blocks: nil, limit: nil)
48
+ start_date:, end_date: nil, time_blocks: nil, day_of_week_time_blocks: nil, limit: nil, exclusion_dates: nil)
46
49
  @time_zone = TZInfo::Timezone.get(time_zone)
47
50
  @days_of_week = days_of_week
48
51
  @time_blocks = time_blocks
@@ -50,6 +53,9 @@ module Periodoxical
50
53
  @start_date = start_date.is_a?(String) ? Date.parse(start_date) : start_date
51
54
  @end_date = end_date.is_a?(String) ? Date.parse(end_date) : end_date
52
55
  @limit = limit
56
+ @exclusion_dates = if exclusion_dates && !exclusion_dates.empty?
57
+ exclusion_dates.map { |ed| Date.parse(ed) }
58
+ end
53
59
  validate!
54
60
  end
55
61
 
@@ -77,7 +83,7 @@ module Periodoxical
77
83
  keep_generating = true
78
84
  while keep_generating
79
85
  day_of_week = day_of_week_long_to_short(current_date.strftime("%A"))
80
- if @day_of_week_time_blocks[day_of_week.to_sym]
86
+ if @day_of_week_time_blocks[day_of_week.to_sym] && !excluded_date?(current_date)
81
87
  time_blocks = @day_of_week_time_blocks[day_of_week.to_sym]
82
88
  time_blocks.each do |tb|
83
89
  times_output << {
@@ -106,7 +112,7 @@ module Periodoxical
106
112
  keep_generating = true
107
113
  while keep_generating
108
114
  day_of_week = day_of_week_long_to_short(current_date.strftime("%A"))
109
- if @days_of_week.include?(day_of_week)
115
+ if @days_of_week.include?(day_of_week) && !excluded_date?(current_date)
110
116
  @time_blocks.each do |tb|
111
117
  times_output << {
112
118
  start: time_str_to_object(current_date, tb[:start_time]),
@@ -182,5 +188,18 @@ module Periodoxical
182
188
  )
183
189
  @time_zone.local_to_utc(date_time).new_offset(@time_zone.current_period.offset.utc_total_offset)
184
190
  end
191
+
192
+ # @param [Date] current_date
193
+ # @return [Boolean]
194
+ # Whether or not the date is excluded
195
+ def excluded_date?(current_date)
196
+ return false unless @exclusion_dates
197
+
198
+ @exclusion_dates.each do |ed|
199
+ return true if current_date == ed
200
+ end
201
+
202
+ false
203
+ end
185
204
  end
186
205
  end
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.2
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Li