active_date_range 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87427c85b995cb2a7425de3a4b41b0df366c0d622e54cd9cbddc0f74b3608eff
4
- data.tar.gz: 7e962cc3041aefb3f231b55b439f86147a07979c86b906a1951fdb7dbf24a1fd
3
+ metadata.gz: f7cc5d1d6cd20c08b30702deb5ecf7822c5cbff0da252e849fa290b90c81c6d8
4
+ data.tar.gz: 55ff9960e377aed53497050259e8ed76891a11cb2be911cf7a0079429f7bedae
5
5
  SHA512:
6
- metadata.gz: 1c8bc3b6b648b5947415152f8c2e6d17d85ad4f9f7ef1cee06ad4b9ab3702259c60c1c6d568721dfb0de1916e06f723ec091e9046d897b3c29afac29a192b401
7
- data.tar.gz: 7e9534d0cb558c9b440b1a05aabcd1a584d27dbb066342dc82cbd2e4afb39b68519b8b6c518e96374ed8852ed8cb41ee3ab0859310f7ef0a84d8f1284c63e643
6
+ metadata.gz: f226583cd68e5f054cc4db0d2fade2ffe7f8825cb659400c07b9e1857c5279856a9fa65e1789ecd4a2b475847937281ce06bed1c4e73df089531ead7d1644900
7
+ data.tar.gz: a44baee259cee6516cd7729f1572cc3c49aa0e6543d09a201f30036e14a44f886297582c63df7110a09d08ac81e4c752d47a15805c08d4e9b0c6fc7338f5cb5c
@@ -0,0 +1,83 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL Advanced"
13
+
14
+ on:
15
+ push:
16
+ branches: [ "main" ]
17
+ pull_request:
18
+ branches: [ "main" ]
19
+ schedule:
20
+ - cron: '25 4 * * 1'
21
+
22
+ jobs:
23
+ analyze:
24
+ name: Analyze (${{ matrix.language }})
25
+ runs-on: ubuntu-latest
26
+ permissions:
27
+ # required for all workflows
28
+ security-events: write
29
+
30
+ # required to fetch internal or private CodeQL packs
31
+ packages: read
32
+
33
+ strategy:
34
+ fail-fast: false
35
+ matrix:
36
+ include:
37
+ - language: actions
38
+ build-mode: none
39
+ - language: ruby
40
+ build-mode: none
41
+ steps:
42
+ - name: Checkout repository
43
+ uses: actions/checkout@v5
44
+
45
+ # Add any setup steps before running the `github/codeql-action/init` action.
46
+ # This includes steps like installing compilers or runtimes (`actions/setup-node`
47
+ # or others). This is typically only required for manual builds.
48
+ # - name: Setup runtime (example)
49
+ # uses: actions/setup-example@v1
50
+
51
+ # Initializes the CodeQL tools for scanning.
52
+ - name: Initialize CodeQL
53
+ uses: github/codeql-action/init@v3
54
+ with:
55
+ languages: ${{ matrix.language }}
56
+ build-mode: ${{ matrix.build-mode }}
57
+ # If you wish to specify custom queries, you can do so here or in a config file.
58
+ # By default, queries listed here will override any specified in a config file.
59
+ # Prefix the list here with "+" to use these queries and those in the config file.
60
+
61
+ # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
62
+ # queries: security-extended,security-and-quality
63
+
64
+ # If the analyze step fails for one of the languages you are analyzing with
65
+ # "We were unable to automatically build your code", modify the matrix above
66
+ # to set the build mode to "manual" for that language. Then modify this step
67
+ # to build your code.
68
+ # ℹ️ Command-line programs to run using the OS shell.
69
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
70
+ - if: matrix.build-mode == 'manual'
71
+ shell: bash
72
+ run: |
73
+ echo 'If you are using a "manual" build mode for one or more of the' \
74
+ 'languages you are analyzing, replace this with the commands to build' \
75
+ 'your code, for example:'
76
+ echo ' make bootstrap'
77
+ echo ' make release'
78
+ exit 1
79
+
80
+ - name: Perform CodeQL Analysis
81
+ uses: github/codeql-action/analyze@v3
82
+ with:
83
+ category: "/language:${{matrix.language}}"
@@ -6,6 +6,8 @@
6
6
  # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
7
 
8
8
  name: Ruby
9
+ permissions:
10
+ contents: read
9
11
 
10
12
  on:
11
13
  push:
@@ -18,10 +20,10 @@ jobs:
18
20
  runs-on: ubuntu-latest
19
21
  strategy:
20
22
  matrix:
21
- ruby-version: ['2.7', '3.0', '3.2']
23
+ ruby-version: ['3.2', '3.3', '3.4']
22
24
 
23
25
  steps:
24
- - uses: actions/checkout@v2
26
+ - uses: actions/checkout@v5
25
27
  - name: Set up Ruby
26
28
  uses: ruby/setup-ruby@v1
27
29
  with:
@@ -34,13 +36,13 @@ jobs:
34
36
  runs-on: ubuntu-latest
35
37
 
36
38
  steps:
37
- - uses: actions/checkout@v2
38
- - name: Set up Ruby 2.7
39
+ - uses: actions/checkout@v5
40
+ - name: Set up Ruby
39
41
  uses: ruby/setup-ruby@v1
40
42
  with:
41
- ruby-version: 2.7
43
+ ruby-version: 3.4
42
44
  - name: Cache gems
43
- uses: actions/cache@v1
45
+ uses: actions/cache@v4
44
46
  with:
45
47
  path: vendor/bundle
46
48
  key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ require:
4
4
  - rubocop-rails
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 2.7
7
+ TargetRubyVersion: 3.4
8
8
  # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
9
9
  # to ignore them, so only the ones explicitly set in this file are enabled.
10
10
  DisabledByDefault: true
data/.ruby-version ADDED
@@ -0,0 +1,2 @@
1
+ 3.4.7
2
+
data/CHANGELOG.md CHANGED
@@ -1,3 +1,44 @@
1
+ ## 0.4.0
2
+
3
+ * Add #stretch_to_end_of_month:
4
+
5
+ ```
6
+ DateRange.parse("20250101..20250112).stretch_to_end_of_month
7
+ # => "20250101..20250131"
8
+ ```
9
+
10
+ *Vincent Oord*
11
+
12
+ * Add exceeds? to check if the period does not exceed a given limit.
13
+
14
+ ```
15
+ DateRange.parse("202501..202503).exceeds?(1.month)
16
+ # => true
17
+
18
+ DateRange.parse("20250101..20250105).exceeds?(1.week)
19
+ # => false
20
+ ```
21
+
22
+ *Vincent Oord*
23
+
24
+ * Update to Ruby 3.4.6 compatibility
25
+
26
+ *Vincent Oord*
27
+
28
+ ## 0.3.3
29
+
30
+ * Add current? to check if the period containts the current date.
31
+
32
+ *Edwin Vlieg*
33
+
34
+ * Add .from_date_and_duration:
35
+
36
+ ```
37
+ DateRange.from_date_and_duration(Date.new(2023, 1, 1), :month) # => Range
38
+ ```
39
+
40
+ *Edwin Vlieg*
41
+
1
42
  ## 0.3.2
2
43
 
3
44
  * Add this_month?, this_quarter? and this_year? to check if a period is the current month, quarter or year
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in active_date_range.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 12.0"
8
+ gem "rake", "~> 13.0"
9
9
  gem "railties", "> 6.1"
10
10
  gem "minitest", "~> 5.0"
11
11
  gem "guard"
data/Gemfile.lock CHANGED
@@ -1,49 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_date_range (0.3.2)
4
+ active_date_range (0.4.0)
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.8)
12
- actionview (= 7.0.8)
13
- activesupport (= 7.0.8)
14
- rack (~> 2.0, >= 2.2.4)
11
+ actionpack (8.0.3)
12
+ actionview (= 8.0.3)
13
+ activesupport (= 8.0.3)
14
+ nokogiri (>= 1.8.5)
15
+ rack (>= 2.2.4)
16
+ rack-session (>= 1.0.1)
15
17
  rack-test (>= 0.6.3)
16
- rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
- actionview (7.0.8)
19
- activesupport (= 7.0.8)
18
+ rails-dom-testing (~> 2.2)
19
+ rails-html-sanitizer (~> 1.6)
20
+ useragent (~> 0.16)
21
+ actionview (8.0.3)
22
+ activesupport (= 8.0.3)
20
23
  builder (~> 3.1)
21
- erubi (~> 1.4)
22
- rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
- activemodel (7.0.8)
25
- activesupport (= 7.0.8)
26
- activesupport (7.0.8)
27
- concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ erubi (~> 1.11)
25
+ rails-dom-testing (~> 2.2)
26
+ rails-html-sanitizer (~> 1.6)
27
+ activemodel (8.0.3)
28
+ activesupport (= 8.0.3)
29
+ activesupport (8.0.3)
30
+ base64
31
+ benchmark (>= 0.3)
32
+ bigdecimal
33
+ concurrent-ruby (~> 1.0, >= 1.3.1)
34
+ connection_pool (>= 2.2.5)
35
+ drb
28
36
  i18n (>= 1.6, < 2)
37
+ logger (>= 1.4.2)
29
38
  minitest (>= 5.1)
30
- tzinfo (~> 2.0)
31
- ast (2.4.2)
32
- base64 (0.1.1)
33
- benchmark-ips (2.12.0)
34
- builder (3.2.4)
39
+ securerandom (>= 0.3)
40
+ tzinfo (~> 2.0, >= 2.0.5)
41
+ uri (>= 0.13.1)
42
+ ast (2.4.3)
43
+ base64 (0.3.0)
44
+ benchmark (0.4.1)
45
+ benchmark-ips (2.14.0)
46
+ bigdecimal (3.3.0)
47
+ builder (3.3.0)
35
48
  coderay (1.1.3)
36
- concurrent-ruby (1.2.2)
49
+ concurrent-ruby (1.3.5)
50
+ connection_pool (2.5.4)
37
51
  crass (1.0.6)
38
- erubi (1.12.0)
39
- ffi (1.16.2)
40
- formatador (1.1.0)
41
- guard (2.18.1)
52
+ date (3.4.1)
53
+ drb (2.2.3)
54
+ erb (5.0.3)
55
+ erubi (1.13.1)
56
+ ffi (1.17.2)
57
+ ffi (1.17.2-x86_64-linux-gnu)
58
+ formatador (1.2.1)
59
+ reline
60
+ guard (2.19.1)
42
61
  formatador (>= 0.2.4)
43
62
  listen (>= 2.7, < 4.0)
63
+ logger (~> 1.6)
44
64
  lumberjack (>= 1.0.12, < 2.0)
45
65
  nenv (~> 0.1)
46
66
  notiffany (~> 0.0)
67
+ ostruct (~> 0.6)
47
68
  pry (>= 0.13.0)
48
69
  shellany (~> 0.0)
49
70
  thor (>= 0.18.1)
@@ -51,90 +72,130 @@ GEM
51
72
  guard-minitest (2.4.6)
52
73
  guard-compat (~> 1.2)
53
74
  minitest (>= 3.0)
54
- i18n (1.14.1)
75
+ i18n (1.14.7)
55
76
  concurrent-ruby (~> 1.0)
56
- json (2.6.3)
57
- language_server-protocol (3.17.0.3)
58
- listen (3.8.0)
77
+ io-console (0.8.1)
78
+ irb (1.15.2)
79
+ pp (>= 0.6.0)
80
+ rdoc (>= 4.0.0)
81
+ reline (>= 0.4.2)
82
+ json (2.15.1)
83
+ language_server-protocol (3.17.0.5)
84
+ lint_roller (1.1.0)
85
+ listen (3.9.0)
59
86
  rb-fsevent (~> 0.10, >= 0.10.3)
60
87
  rb-inotify (~> 0.9, >= 0.9.10)
61
- loofah (2.21.3)
88
+ logger (1.7.0)
89
+ loofah (2.24.1)
62
90
  crass (~> 1.0.2)
63
91
  nokogiri (>= 1.12.0)
64
- lumberjack (1.2.9)
65
- memory_profiler (1.0.1)
66
- method_source (1.0.0)
67
- mini_portile2 (2.8.4)
68
- minitest (5.20.0)
92
+ lumberjack (1.4.2)
93
+ memory_profiler (1.1.0)
94
+ method_source (1.1.0)
95
+ mini_portile2 (2.8.9)
96
+ minitest (5.25.5)
69
97
  nenv (0.3.0)
70
- nokogiri (1.15.4)
98
+ nokogiri (1.18.10)
71
99
  mini_portile2 (~> 2.8.2)
72
100
  racc (~> 1.4)
101
+ nokogiri (1.18.10-x86_64-linux-gnu)
102
+ racc (~> 1.4)
73
103
  notiffany (0.1.3)
74
104
  nenv (~> 0.1)
75
105
  shellany (~> 0.0)
76
- parallel (1.23.0)
77
- parser (3.2.2.3)
106
+ ostruct (0.6.3)
107
+ parallel (1.27.0)
108
+ parser (3.3.9.0)
78
109
  ast (~> 2.4.1)
79
110
  racc
80
- pry (0.14.2)
111
+ pp (0.6.3)
112
+ prettyprint
113
+ prettyprint (0.2.0)
114
+ prism (1.5.1)
115
+ pry (0.15.2)
81
116
  coderay (~> 1.1)
82
117
  method_source (~> 1.0)
83
- racc (1.7.1)
84
- rack (2.2.8)
85
- rack-test (2.1.0)
118
+ psych (5.2.6)
119
+ date
120
+ stringio
121
+ racc (1.8.1)
122
+ rack (3.2.2)
123
+ rack-session (2.1.1)
124
+ base64 (>= 0.1.0)
125
+ rack (>= 3.0.0)
126
+ rack-test (2.2.0)
86
127
  rack (>= 1.3)
87
- rails-dom-testing (2.2.0)
128
+ rackup (2.2.1)
129
+ rack (>= 3)
130
+ rails-dom-testing (2.3.0)
88
131
  activesupport (>= 5.0.0)
89
132
  minitest
90
133
  nokogiri (>= 1.6)
91
- rails-html-sanitizer (1.6.0)
134
+ rails-html-sanitizer (1.6.2)
92
135
  loofah (~> 2.21)
93
- nokogiri (~> 1.14)
94
- railties (7.0.8)
95
- actionpack (= 7.0.8)
96
- activesupport (= 7.0.8)
97
- method_source
136
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
137
+ railties (8.0.3)
138
+ actionpack (= 8.0.3)
139
+ activesupport (= 8.0.3)
140
+ irb (~> 1.13)
141
+ rackup (>= 1.0.0)
98
142
  rake (>= 12.2)
99
- thor (~> 1.0)
100
- zeitwerk (~> 2.5)
143
+ thor (~> 1.0, >= 1.2.2)
144
+ tsort (>= 0.2)
145
+ zeitwerk (~> 2.6)
101
146
  rainbow (3.1.1)
102
- rake (12.3.3)
147
+ rake (13.3.0)
103
148
  rb-fsevent (0.11.2)
104
- rb-inotify (0.10.1)
149
+ rb-inotify (0.11.1)
105
150
  ffi (~> 1.0)
106
- regexp_parser (2.8.1)
107
- rexml (3.2.6)
108
- rubocop (1.56.3)
109
- base64 (~> 0.1.1)
151
+ rdoc (6.15.0)
152
+ erb
153
+ psych (>= 4.0.0)
154
+ tsort
155
+ regexp_parser (2.11.3)
156
+ reline (0.6.2)
157
+ io-console (~> 0.5)
158
+ rubocop (1.81.1)
110
159
  json (~> 2.3)
111
- language_server-protocol (>= 3.17.0)
160
+ language_server-protocol (~> 3.17.0.2)
161
+ lint_roller (~> 1.1.0)
112
162
  parallel (~> 1.10)
113
- parser (>= 3.2.2.3)
163
+ parser (>= 3.3.0.2)
114
164
  rainbow (>= 2.2.2, < 4.0)
115
- regexp_parser (>= 1.8, < 3.0)
116
- rexml (>= 3.2.5, < 4.0)
117
- rubocop-ast (>= 1.28.1, < 2.0)
165
+ regexp_parser (>= 2.9.3, < 3.0)
166
+ rubocop-ast (>= 1.47.1, < 2.0)
118
167
  ruby-progressbar (~> 1.7)
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)
125
- rubocop (>= 1.7.0, < 2.0)
126
- rubocop-ast (>= 0.4.0)
127
- rubocop-rails (2.21.1)
168
+ unicode-display_width (>= 2.4.0, < 4.0)
169
+ rubocop-ast (1.47.1)
170
+ parser (>= 3.3.7.2)
171
+ prism (~> 1.4)
172
+ rubocop-packaging (0.6.0)
173
+ lint_roller (~> 1.1.0)
174
+ rubocop (>= 1.72.1, < 2.0)
175
+ rubocop-performance (1.26.0)
176
+ lint_roller (~> 1.1)
177
+ rubocop (>= 1.75.0, < 2.0)
178
+ rubocop-ast (>= 1.44.0, < 2.0)
179
+ rubocop-rails (2.33.4)
128
180
  activesupport (>= 4.2.0)
181
+ lint_roller (~> 1.1)
129
182
  rack (>= 1.1)
130
- rubocop (>= 1.33.0, < 2.0)
183
+ rubocop (>= 1.75.0, < 2.0)
184
+ rubocop-ast (>= 1.44.0, < 2.0)
131
185
  ruby-progressbar (1.13.0)
186
+ securerandom (0.4.1)
132
187
  shellany (0.0.1)
133
- thor (1.2.2)
188
+ stringio (3.1.7)
189
+ thor (1.4.0)
190
+ tsort (0.2.0)
134
191
  tzinfo (2.0.6)
135
192
  concurrent-ruby (~> 1.0)
136
- unicode-display_width (2.4.2)
137
- zeitwerk (2.6.12)
193
+ unicode-display_width (3.2.0)
194
+ unicode-emoji (~> 4.1)
195
+ unicode-emoji (4.1.0)
196
+ uri (1.0.4)
197
+ useragent (0.16.11)
198
+ zeitwerk (2.7.3)
138
199
 
139
200
  PLATFORMS
140
201
  ruby
@@ -150,7 +211,7 @@ DEPENDENCIES
150
211
  minitest (~> 5.0)
151
212
  pry
152
213
  railties (> 6.1)
153
- rake (~> 12.0)
214
+ rake (~> 13.0)
154
215
  rubocop
155
216
  rubocop-packaging
156
217
  rubocop-performance
data/SECURITY.md ADDED
@@ -0,0 +1,15 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 0.4.x | :white_check_mark: |
11
+ | < 0.3.3 | :x: |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ Please refer to https://www.moneybird.nl/security/ for our Responsible Disclosure policy.
@@ -11,7 +11,8 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "DateRange for ActiveSupport"
12
12
  spec.description = "ActiveDateRange provides a range of dates with a powerful API to manipulate and use date ranges in your software."
13
13
  spec.homepage = "https://github.com/moneybird/active-date-range"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
15
16
 
16
17
  spec.metadata["homepage_uri"] = spec.homepage
17
18
  spec.metadata["source_code_uri"] = "https://github.com/moneybird/active-date-range"
@@ -26,12 +27,12 @@ Gem::Specification.new do |spec|
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
28
  spec.require_paths = ["lib"]
28
29
 
29
- spec.add_dependency "activesupport", "> 6.1"
30
- spec.add_dependency "i18n"
30
+ spec.add_runtime_dependency "activesupport", "~> 6.1"
31
+ spec.add_runtime_dependency "i18n", "~> 1.6"
31
32
 
32
- spec.add_development_dependency "rubocop"
33
- spec.add_development_dependency "rubocop-packaging"
34
- spec.add_development_dependency "rubocop-performance"
35
- spec.add_development_dependency "rubocop-rails"
36
- spec.add_development_dependency "activemodel"
33
+ spec.add_development_dependency "rubocop", "~> 1.18"
34
+ spec.add_development_dependency "rubocop-packaging", "~> 0.6"
35
+ spec.add_development_dependency "rubocop-performance", "~> 1.26"
36
+ spec.add_development_dependency "rubocop-rails", "~> 2.33"
37
+ spec.add_development_dependency "activemodel", "~> 6.1"
37
38
  end
@@ -31,6 +31,7 @@ module ActiveDateRange
31
31
  # - A begin and end date: <tt>YYYYMMDD..YYYYMMDD</tt>
32
32
  # - A begin and end month: <tt>YYYYMM..YYYYMM</tt>
33
33
  def self.parse(input)
34
+ return nil if input.nil?
34
35
  return DateRange.new(input) if input.kind_of?(Range)
35
36
  return SHORTHANDS[input.to_sym].call if SHORTHANDS.key?(input.to_sym)
36
37
 
@@ -58,6 +59,11 @@ module ActiveDateRange
58
59
  raise InvalidDateRangeFormat
59
60
  end
60
61
 
62
+ def self.from_date_and_duration(date, duration)
63
+ duration = 1.send(duration) if duration.kind_of?(Symbol)
64
+ new(date, date + duration - 1.day)
65
+ end
66
+
61
67
  private_class_method :parse_date
62
68
 
63
69
  # Initializes a new DateRange. Accepts both a begin and end date or a range of dates.
@@ -232,26 +238,15 @@ module ActiveDateRange
232
238
  end
233
239
  end
234
240
 
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
241
+ def current?
242
+ memoize(:@current) do
243
+ cover?(Time.zone.today)
239
244
  end
240
245
  end
241
246
 
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
254
- end
247
+ alias :this_month? :current?
248
+ alias :this_quarter? :current?
249
+ alias :this_year? :current?
255
250
 
256
251
  # Returns true when the date range is before the given date. Accepts both a <tt>Date</tt>
257
252
  # and <tt>DateRange</tt> as input.
@@ -404,6 +399,18 @@ module ActiveDateRange
404
399
  cover?(other)
405
400
  end
406
401
 
402
+ def stretch_to_end_of_month
403
+ return self if self.end.present? && self.end == self.end.at_end_of_month
404
+
405
+ side_to_stretch = boundless? ? self.begin : self.end
406
+
407
+ DateRange.new(self.begin, side_to_stretch.at_end_of_month)
408
+ end
409
+
410
+ def exceeds?(limit)
411
+ self.days > limit.in_days.ceil
412
+ end
413
+
407
414
  private
408
415
  def grouped_collection(granularity, amount: 1)
409
416
  raise UnknownGranularity, "Unknown granularity #{granularity}. Valid are: month, quarter and year" unless %w[month quarter year].include?(granularity.to_s)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDateRange
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,113 +1,112 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_date_range
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Vlieg
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-09-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">"
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: '6.1'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">"
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: '6.1'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: i18n
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - ">="
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
32
+ version: '1.6'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - ">="
37
+ - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '0'
39
+ version: '1.6'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rubocop
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - ">="
44
+ - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '0'
46
+ version: '1.18'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - ">="
51
+ - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '0'
53
+ version: '1.18'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: rubocop-packaging
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - ">="
58
+ - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '0'
60
+ version: '0.6'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
- - - ">="
65
+ - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '0'
67
+ version: '0.6'
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: rubocop-performance
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - ">="
72
+ - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '0'
74
+ version: '1.26'
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - ">="
79
+ - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '0'
81
+ version: '1.26'
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: rubocop-rails
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
- - - ">="
86
+ - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '0'
88
+ version: '2.33'
90
89
  type: :development
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
- - - ">="
93
+ - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: '0'
95
+ version: '2.33'
97
96
  - !ruby/object:Gem::Dependency
98
97
  name: activemodel
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
- - - ">="
100
+ - - "~>"
102
101
  - !ruby/object:Gem::Version
103
- version: '0'
102
+ version: '6.1'
104
103
  type: :development
105
104
  prerelease: false
106
105
  version_requirements: !ruby/object:Gem::Requirement
107
106
  requirements:
108
- - - ">="
107
+ - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '0'
109
+ version: '6.1'
111
110
  description: ActiveDateRange provides a range of dates with a powerful API to manipulate
112
111
  and use date ranges in your software.
113
112
  email:
@@ -116,10 +115,11 @@ executables: []
116
115
  extensions: []
117
116
  extra_rdoc_files: []
118
117
  files:
118
+ - ".github/workflows/codeql.yml"
119
119
  - ".github/workflows/ruby.yml"
120
120
  - ".gitignore"
121
121
  - ".rubocop.yml"
122
- - ".travis.yml"
122
+ - ".ruby-version"
123
123
  - CHANGELOG.md
124
124
  - Gemfile
125
125
  - Gemfile.lock
@@ -127,6 +127,7 @@ files:
127
127
  - LICENSE
128
128
  - README.md
129
129
  - Rakefile
130
+ - SECURITY.md
130
131
  - active_date_range.gemspec
131
132
  - bin/console
132
133
  - bin/setup
@@ -140,12 +141,12 @@ files:
140
141
  - lib/active_date_range/locale/en.yml
141
142
  - lib/active_date_range/version.rb
142
143
  homepage: https://github.com/moneybird/active-date-range
143
- licenses: []
144
+ licenses:
145
+ - MIT
144
146
  metadata:
145
147
  homepage_uri: https://github.com/moneybird/active-date-range
146
148
  source_code_uri: https://github.com/moneybird/active-date-range
147
149
  changelog_uri: https://github.com/moneybird/active-date-range/blob/main/CHANGELOG.md
148
- post_install_message:
149
150
  rdoc_options: []
150
151
  require_paths:
151
152
  - lib
@@ -153,15 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
154
  requirements:
154
155
  - - ">="
155
156
  - !ruby/object:Gem::Version
156
- version: 2.7.0
157
+ version: 3.2.0
157
158
  required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  requirements:
159
160
  - - ">="
160
161
  - !ruby/object:Gem::Version
161
162
  version: '0'
162
163
  requirements: []
163
- rubygems_version: 3.3.26
164
- signing_key:
164
+ rubygems_version: 3.6.9
165
165
  specification_version: 4
166
166
  summary: DateRange for ActiveSupport
167
167
  test_files: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.1
6
- before_install: gem install bundler -v 2.1.4