active_date_range 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -5
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +75 -59
- data/lib/active_date_range/date_range.rb +93 -34
- data/lib/active_date_range/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87427c85b995cb2a7425de3a4b41b0df366c0d622e54cd9cbddc0f74b3608eff
|
4
|
+
data.tar.gz: 7e962cc3041aefb3f231b55b439f86147a07979c86b906a1951fdb7dbf24a1fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c8bc3b6b648b5947415152f8c2e6d17d85ad4f9f7ef1cee06ad4b9ab3702259c60c1c6d568721dfb0de1916e06f723ec091e9046d897b3c29afac29a192b401
|
7
|
+
data.tar.gz: 7e9534d0cb558c9b440b1a05aabcd1a584d27dbb066342dc82cbd2e4afb39b68519b8b6c518e96374ed8852ed8cb41ee3ab0859310f7ef0a84d8f1284c63e643
|
data/.github/workflows/ruby.yml
CHANGED
@@ -18,15 +18,12 @@ jobs:
|
|
18
18
|
runs-on: ubuntu-latest
|
19
19
|
strategy:
|
20
20
|
matrix:
|
21
|
-
ruby-version: ['2.7', '3.0']
|
21
|
+
ruby-version: ['2.7', '3.0', '3.2']
|
22
22
|
|
23
23
|
steps:
|
24
24
|
- uses: actions/checkout@v2
|
25
25
|
- name: Set up Ruby
|
26
|
-
|
27
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
28
|
-
# uses: ruby/setup-ruby@v1
|
29
|
-
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
26
|
+
uses: ruby/setup-ruby@v1
|
30
27
|
with:
|
31
28
|
ruby-version: ${{ matrix.ruby-version }}
|
32
29
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,42 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_date_range (0.3.
|
4
|
+
active_date_range (0.3.2)
|
5
5
|
activesupport (> 6.1)
|
6
6
|
i18n
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (7.0.
|
12
|
-
actionview (= 7.0.
|
13
|
-
activesupport (= 7.0.
|
14
|
-
rack (~> 2.0, >= 2.2.
|
11
|
+
actionpack (7.0.8)
|
12
|
+
actionview (= 7.0.8)
|
13
|
+
activesupport (= 7.0.8)
|
14
|
+
rack (~> 2.0, >= 2.2.4)
|
15
15
|
rack-test (>= 0.6.3)
|
16
16
|
rails-dom-testing (~> 2.0)
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
-
actionview (7.0.
|
19
|
-
activesupport (= 7.0.
|
18
|
+
actionview (7.0.8)
|
19
|
+
activesupport (= 7.0.8)
|
20
20
|
builder (~> 3.1)
|
21
21
|
erubi (~> 1.4)
|
22
22
|
rails-dom-testing (~> 2.0)
|
23
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
-
activemodel (7.0.
|
25
|
-
activesupport (= 7.0.
|
26
|
-
activesupport (7.0.
|
24
|
+
activemodel (7.0.8)
|
25
|
+
activesupport (= 7.0.8)
|
26
|
+
activesupport (7.0.8)
|
27
27
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
28
28
|
i18n (>= 1.6, < 2)
|
29
29
|
minitest (>= 5.1)
|
30
30
|
tzinfo (~> 2.0)
|
31
31
|
ast (2.4.2)
|
32
|
+
base64 (0.1.1)
|
33
|
+
benchmark-ips (2.12.0)
|
32
34
|
builder (3.2.4)
|
33
35
|
coderay (1.1.3)
|
34
|
-
concurrent-ruby (1.
|
36
|
+
concurrent-ruby (1.2.2)
|
35
37
|
crass (1.0.6)
|
36
|
-
erubi (1.
|
37
|
-
ffi (1.
|
38
|
-
formatador (
|
39
|
-
guard (2.18.
|
38
|
+
erubi (1.12.0)
|
39
|
+
ffi (1.16.2)
|
40
|
+
formatador (1.1.0)
|
41
|
+
guard (2.18.1)
|
40
42
|
formatador (>= 0.2.4)
|
41
43
|
listen (>= 2.7, < 4.0)
|
42
44
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -49,88 +51,102 @@ GEM
|
|
49
51
|
guard-minitest (2.4.6)
|
50
52
|
guard-compat (~> 1.2)
|
51
53
|
minitest (>= 3.0)
|
52
|
-
i18n (1.
|
54
|
+
i18n (1.14.1)
|
53
55
|
concurrent-ruby (~> 1.0)
|
54
|
-
|
56
|
+
json (2.6.3)
|
57
|
+
language_server-protocol (3.17.0.3)
|
58
|
+
listen (3.8.0)
|
55
59
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
56
60
|
rb-inotify (~> 0.9, >= 0.9.10)
|
57
|
-
loofah (2.
|
61
|
+
loofah (2.21.3)
|
58
62
|
crass (~> 1.0.2)
|
59
|
-
nokogiri (>= 1.
|
60
|
-
lumberjack (1.2.
|
63
|
+
nokogiri (>= 1.12.0)
|
64
|
+
lumberjack (1.2.9)
|
65
|
+
memory_profiler (1.0.1)
|
61
66
|
method_source (1.0.0)
|
62
|
-
|
67
|
+
mini_portile2 (2.8.4)
|
68
|
+
minitest (5.20.0)
|
63
69
|
nenv (0.3.0)
|
64
|
-
nokogiri (1.
|
70
|
+
nokogiri (1.15.4)
|
71
|
+
mini_portile2 (~> 2.8.2)
|
65
72
|
racc (~> 1.4)
|
66
73
|
notiffany (0.1.3)
|
67
74
|
nenv (~> 0.1)
|
68
75
|
shellany (~> 0.0)
|
69
|
-
parallel (1.
|
70
|
-
parser (3.
|
76
|
+
parallel (1.23.0)
|
77
|
+
parser (3.2.2.3)
|
71
78
|
ast (~> 2.4.1)
|
72
|
-
|
79
|
+
racc
|
80
|
+
pry (0.14.2)
|
73
81
|
coderay (~> 1.1)
|
74
82
|
method_source (~> 1.0)
|
75
|
-
racc (1.
|
76
|
-
rack (2.2.
|
77
|
-
rack-test (
|
78
|
-
rack (>= 1.
|
79
|
-
rails-dom-testing (2.0
|
80
|
-
activesupport (>=
|
83
|
+
racc (1.7.1)
|
84
|
+
rack (2.2.8)
|
85
|
+
rack-test (2.1.0)
|
86
|
+
rack (>= 1.3)
|
87
|
+
rails-dom-testing (2.2.0)
|
88
|
+
activesupport (>= 5.0.0)
|
89
|
+
minitest
|
81
90
|
nokogiri (>= 1.6)
|
82
|
-
rails-html-sanitizer (1.
|
83
|
-
loofah (~> 2.
|
84
|
-
|
85
|
-
|
86
|
-
|
91
|
+
rails-html-sanitizer (1.6.0)
|
92
|
+
loofah (~> 2.21)
|
93
|
+
nokogiri (~> 1.14)
|
94
|
+
railties (7.0.8)
|
95
|
+
actionpack (= 7.0.8)
|
96
|
+
activesupport (= 7.0.8)
|
87
97
|
method_source
|
88
|
-
rake (>=
|
98
|
+
rake (>= 12.2)
|
89
99
|
thor (~> 1.0)
|
90
|
-
zeitwerk (~> 2.5
|
91
|
-
rainbow (3.
|
100
|
+
zeitwerk (~> 2.5)
|
101
|
+
rainbow (3.1.1)
|
92
102
|
rake (12.3.3)
|
93
|
-
rb-fsevent (0.11.
|
103
|
+
rb-fsevent (0.11.2)
|
94
104
|
rb-inotify (0.10.1)
|
95
105
|
ffi (~> 1.0)
|
96
|
-
regexp_parser (2.
|
97
|
-
rexml (3.2.
|
98
|
-
rubocop (1.
|
106
|
+
regexp_parser (2.8.1)
|
107
|
+
rexml (3.2.6)
|
108
|
+
rubocop (1.56.3)
|
109
|
+
base64 (~> 0.1.1)
|
110
|
+
json (~> 2.3)
|
111
|
+
language_server-protocol (>= 3.17.0)
|
99
112
|
parallel (~> 1.10)
|
100
|
-
parser (>= 3.
|
113
|
+
parser (>= 3.2.2.3)
|
101
114
|
rainbow (>= 2.2.2, < 4.0)
|
102
115
|
regexp_parser (>= 1.8, < 3.0)
|
103
|
-
rexml
|
104
|
-
rubocop-ast (>= 1.
|
116
|
+
rexml (>= 3.2.5, < 4.0)
|
117
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
105
118
|
ruby-progressbar (~> 1.7)
|
106
|
-
unicode-display_width (>=
|
107
|
-
rubocop-ast (1.
|
108
|
-
parser (>= 3.
|
109
|
-
rubocop-packaging (0.5.
|
110
|
-
rubocop (>=
|
111
|
-
rubocop-performance (1.
|
119
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
120
|
+
rubocop-ast (1.29.0)
|
121
|
+
parser (>= 3.2.1.0)
|
122
|
+
rubocop-packaging (0.5.2)
|
123
|
+
rubocop (>= 1.33, < 2.0)
|
124
|
+
rubocop-performance (1.19.1)
|
112
125
|
rubocop (>= 1.7.0, < 2.0)
|
113
126
|
rubocop-ast (>= 0.4.0)
|
114
|
-
rubocop-rails (2.
|
127
|
+
rubocop-rails (2.21.1)
|
115
128
|
activesupport (>= 4.2.0)
|
116
129
|
rack (>= 1.1)
|
117
|
-
rubocop (>= 1.
|
118
|
-
ruby-progressbar (1.
|
130
|
+
rubocop (>= 1.33.0, < 2.0)
|
131
|
+
ruby-progressbar (1.13.0)
|
119
132
|
shellany (0.0.1)
|
120
|
-
thor (1.
|
121
|
-
tzinfo (2.0.
|
133
|
+
thor (1.2.2)
|
134
|
+
tzinfo (2.0.6)
|
122
135
|
concurrent-ruby (~> 1.0)
|
123
|
-
unicode-display_width (2.
|
124
|
-
zeitwerk (2.
|
136
|
+
unicode-display_width (2.4.2)
|
137
|
+
zeitwerk (2.6.12)
|
125
138
|
|
126
139
|
PLATFORMS
|
140
|
+
ruby
|
127
141
|
x86_64-linux
|
128
142
|
|
129
143
|
DEPENDENCIES
|
130
144
|
active_date_range!
|
131
145
|
activemodel
|
146
|
+
benchmark-ips
|
132
147
|
guard
|
133
148
|
guard-minitest
|
149
|
+
memory_profiler
|
134
150
|
minitest (~> 5.0)
|
135
151
|
pry
|
136
152
|
railties (> 6.1)
|
@@ -128,82 +128,129 @@ module ActiveDateRange
|
|
128
128
|
|
129
129
|
# Returns true when begin of the range is at the beginning of the month
|
130
130
|
def begin_at_beginning_of_month?
|
131
|
-
|
131
|
+
memoize(:@begin_at_beginning_of_month) do
|
132
|
+
self.begin.present? && self.begin.day == 1
|
133
|
+
end
|
132
134
|
end
|
133
135
|
|
134
136
|
# Returns true when begin of the range is at the beginning of the quarter
|
135
137
|
def begin_at_beginning_of_quarter?
|
136
|
-
|
138
|
+
memoize(:@begin_at_beginning_of_quarter) do
|
139
|
+
self.begin.present? && begin_at_beginning_of_month? && [1, 4, 7, 10].include?(self.begin.month)
|
140
|
+
end
|
137
141
|
end
|
138
142
|
|
139
143
|
# Returns true when begin of the range is at the beginning of the year
|
140
144
|
def begin_at_beginning_of_year?
|
141
|
-
|
145
|
+
memoize(:@begin_at_beginning_of_year) do
|
146
|
+
self.begin.present? && begin_at_beginning_of_month? && self.begin.month == 1
|
147
|
+
end
|
142
148
|
end
|
143
149
|
|
144
150
|
# Returns true when begin of the range is at the beginning of the week
|
145
151
|
def begin_at_beginning_of_week?
|
146
|
-
|
152
|
+
memoize(:@begin_at_beginning_of_week) do
|
153
|
+
self.begin.present? && self.begin == self.begin.at_beginning_of_week
|
154
|
+
end
|
147
155
|
end
|
148
156
|
|
149
157
|
# Returns true when the range is exactly one month long
|
150
158
|
def one_month?
|
151
|
-
(
|
152
|
-
|
153
|
-
|
159
|
+
memoize(:@one_month) do
|
160
|
+
(28..31).cover?(days) &&
|
161
|
+
begin_at_beginning_of_month? &&
|
162
|
+
self.end == self.begin.at_end_of_month
|
163
|
+
end
|
154
164
|
end
|
155
165
|
|
156
166
|
# Returns true when the range is exactly one quarter long
|
157
167
|
def one_quarter?
|
158
|
-
(
|
159
|
-
|
160
|
-
|
168
|
+
memoize(:@one_quarter) do
|
169
|
+
(90..92).cover?(days) &&
|
170
|
+
begin_at_beginning_of_quarter? &&
|
171
|
+
self.end == self.begin.at_end_of_quarter
|
172
|
+
end
|
161
173
|
end
|
162
174
|
|
163
175
|
# Returns true when the range is exactly one year long
|
164
176
|
def one_year?
|
165
|
-
(
|
166
|
-
|
167
|
-
|
177
|
+
memoize(:@one_year) do
|
178
|
+
(365..366).cover?(days) &&
|
179
|
+
begin_at_beginning_of_year? &&
|
180
|
+
self.end == self.begin.at_end_of_year
|
181
|
+
end
|
168
182
|
end
|
169
183
|
|
170
184
|
def one_week?
|
171
|
-
|
172
|
-
|
173
|
-
|
185
|
+
memoize(:@one_week) do
|
186
|
+
days == 7 &&
|
187
|
+
begin_at_beginning_of_week? &&
|
188
|
+
self.end == self.begin.at_end_of_week
|
189
|
+
end
|
174
190
|
end
|
175
191
|
|
176
192
|
# Returns true when the range is exactly one or more months long
|
177
193
|
def full_month?
|
178
|
-
|
194
|
+
memoize(:@full_month) do
|
195
|
+
begin_at_beginning_of_month? && self.end.present? && self.end == self.end.at_end_of_month
|
196
|
+
end
|
179
197
|
end
|
180
198
|
|
181
199
|
alias :full_months? :full_month?
|
182
200
|
|
183
201
|
# Returns true when the range is exactly one or more quarters long
|
184
202
|
def full_quarter?
|
185
|
-
|
203
|
+
memoize(:@full_quarter) do
|
204
|
+
begin_at_beginning_of_quarter? && self.end.present? && self.end == self.end.at_end_of_quarter
|
205
|
+
end
|
186
206
|
end
|
187
207
|
|
188
208
|
alias :full_quarters? :full_quarter?
|
189
209
|
|
190
210
|
# Returns true when the range is exactly one or more years long
|
191
211
|
def full_year?
|
192
|
-
|
212
|
+
memoize(:@full_year) do
|
213
|
+
begin_at_beginning_of_year? && self.end.present? && self.end == self.end.at_end_of_year
|
214
|
+
end
|
193
215
|
end
|
194
216
|
|
195
217
|
alias :full_years? :full_year?
|
196
218
|
|
197
219
|
# Returns true when the range is exactly one or more weeks long
|
198
220
|
def full_week?
|
199
|
-
|
221
|
+
memoize(:@full_week) do
|
222
|
+
begin_at_beginning_of_week? && self.end.present? && self.end == self.end.at_end_of_week
|
223
|
+
end
|
200
224
|
end
|
201
225
|
|
202
226
|
alias :full_weeks? :full_week?
|
203
227
|
|
204
228
|
# Returns true when begin and end are in the same year
|
205
229
|
def same_year?
|
206
|
-
|
230
|
+
memoize(:@same_year) do
|
231
|
+
!boundless? && self.begin.year == self.end.year
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
# Return true when the range is equal to the current month
|
236
|
+
def this_month?
|
237
|
+
memoize(:@this_month) do
|
238
|
+
self == DateRange.this_month
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
# Return true when the range is equal to the current quarter
|
243
|
+
def this_quarter?
|
244
|
+
memoize(:@this_quarter) do
|
245
|
+
self == DateRange.this_quarter
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Return true when the range is equal to the current year
|
250
|
+
def this_year?
|
251
|
+
memoize(:@this_year) do
|
252
|
+
self == DateRange.this_year
|
253
|
+
end
|
207
254
|
end
|
208
255
|
|
209
256
|
# Returns true when the date range is before the given date. Accepts both a <tt>Date</tt>
|
@@ -227,14 +274,16 @@ module ActiveDateRange
|
|
227
274
|
# DateRange.this_quarter.granularity # => :quarter
|
228
275
|
# DateRange.this_year.granularity # => :year
|
229
276
|
def granularity
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
277
|
+
memoize(:@granularity) do
|
278
|
+
if one_year?
|
279
|
+
:year
|
280
|
+
elsif one_quarter?
|
281
|
+
:quarter
|
282
|
+
elsif one_month?
|
283
|
+
:month
|
284
|
+
elsif one_week?
|
285
|
+
:week
|
286
|
+
end
|
238
287
|
end
|
239
288
|
end
|
240
289
|
|
@@ -242,11 +291,13 @@ module ActiveDateRange
|
|
242
291
|
# a range of 2021-01-01..2021-12-31 will return `this_year` when the current date
|
243
292
|
# is somewhere in 2021.
|
244
293
|
def relative_param
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
294
|
+
memoize(:@relative_param) do
|
295
|
+
SHORTHANDS
|
296
|
+
.select { |key, _| key.end_with?(granularity.to_s) }
|
297
|
+
.find { |key, range| self == range.call }
|
298
|
+
&.first
|
299
|
+
&.to_s
|
300
|
+
end
|
250
301
|
end
|
251
302
|
|
252
303
|
# Returns a param representation of the date range. When `relative` is true,
|
@@ -364,5 +415,13 @@ module ActiveDateRange
|
|
364
415
|
.slice_before { |_, index| index % amount == 0 }
|
365
416
|
.map { |group| group.map(&:first).inject(:+) }
|
366
417
|
end
|
418
|
+
|
419
|
+
def memoize(name)
|
420
|
+
if instance_variable_defined?(name)
|
421
|
+
instance_variable_get(name)
|
422
|
+
else
|
423
|
+
instance_variable_set(name, yield)
|
424
|
+
end
|
425
|
+
end
|
367
426
|
end
|
368
427
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_date_range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Vlieg
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -145,7 +145,7 @@ metadata:
|
|
145
145
|
homepage_uri: https://github.com/moneybird/active-date-range
|
146
146
|
source_code_uri: https://github.com/moneybird/active-date-range
|
147
147
|
changelog_uri: https://github.com/moneybird/active-date-range/blob/main/CHANGELOG.md
|
148
|
-
post_install_message:
|
148
|
+
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|
151
151
|
- lib
|
@@ -160,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
164
|
-
signing_key:
|
163
|
+
rubygems_version: 3.3.26
|
164
|
+
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: DateRange for ActiveSupport
|
167
167
|
test_files: []
|