active_period 6.2.0 → 7.0.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 +4 -4
- data/Gemfile.lock +52 -12
- data/README.md +15 -11
- data/active_period.gemspec +5 -2
- data/lib/active_period/version.rb +1 -1
- data/lib/active_period.rb +2 -0
- data/lib/period.rb +26 -13
- metadata +29 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f52b743020890ffb49224e7b0dd129901233a4d1cdd639d412a88872c66b97d0
|
4
|
+
data.tar.gz: 0eb862ce0e5aa128ce81fd93e28dd887c64f0f70ec000c9dd7988e281288be39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce08f3f5b1b10347469b43a832d525bec3a470b09e798539f84bc80b4aca768898734565acadf5600670fcbb9e7a3e6a427b9c4fcbccc402e5b5c0109a05a62
|
7
|
+
data.tar.gz: 5e3dcdb1f0328b1baf28ad298e951d893c9e9102faa703890ba47f3c6983947c666dad61e810364ff2bb2b4648542be859d7bfee5f081472da4bb7d3293da07a
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,65 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_period (
|
5
|
-
activesupport (~> 5)
|
4
|
+
active_period (7.0.0)
|
5
|
+
activesupport (~> 7, >= 5)
|
6
6
|
i18n (~> 1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (
|
11
|
+
activesupport (7.0.2.2)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>=
|
14
|
-
minitest (
|
15
|
-
tzinfo (~>
|
16
|
-
|
17
|
-
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
builder (3.2.4)
|
17
|
+
concurrent-ruby (1.1.9)
|
18
|
+
cucumber (7.0.0)
|
19
|
+
builder (~> 3.2, >= 3.2.4)
|
20
|
+
cucumber-core (~> 10.0, >= 10.0.1)
|
21
|
+
cucumber-create-meta (~> 6.0, >= 6.0.1)
|
22
|
+
cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
|
23
|
+
cucumber-gherkin (~> 20.0, >= 20.0.1)
|
24
|
+
cucumber-html-formatter (~> 16.0, >= 16.0.1)
|
25
|
+
cucumber-messages (~> 17.0, >= 17.0.1)
|
26
|
+
cucumber-wire (~> 6.0, >= 6.0.1)
|
27
|
+
diff-lcs (~> 1.4, >= 1.4.4)
|
28
|
+
mime-types (~> 3.3, >= 3.3.1)
|
29
|
+
multi_test (~> 0.1, >= 0.1.2)
|
30
|
+
sys-uname (~> 1.2, >= 1.2.2)
|
31
|
+
cucumber-core (10.0.1)
|
32
|
+
cucumber-gherkin (~> 20.0, >= 20.0.1)
|
33
|
+
cucumber-messages (~> 17.0, >= 17.0.1)
|
34
|
+
cucumber-tag-expressions (~> 3.0, >= 3.0.1)
|
35
|
+
cucumber-create-meta (6.0.1)
|
36
|
+
cucumber-messages (~> 17.0, >= 17.0.1)
|
37
|
+
sys-uname (~> 1.2, >= 1.2.2)
|
38
|
+
cucumber-cucumber-expressions (12.1.1)
|
39
|
+
cucumber-gherkin (20.0.1)
|
40
|
+
cucumber-messages (~> 17.0, >= 17.0.1)
|
41
|
+
cucumber-html-formatter (16.0.1)
|
42
|
+
cucumber-messages (~> 17.0, >= 17.0.1)
|
43
|
+
cucumber-messages (17.0.1)
|
44
|
+
cucumber-tag-expressions (3.0.1)
|
45
|
+
cucumber-wire (6.0.1)
|
46
|
+
cucumber-core (~> 10.0, >= 10.0.1)
|
47
|
+
cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
|
48
|
+
cucumber-messages (~> 17.0, >= 17.0.1)
|
49
|
+
diff-lcs (1.4.4)
|
50
|
+
ffi (1.15.3)
|
51
|
+
i18n (1.10.0)
|
18
52
|
concurrent-ruby (~> 1.0)
|
19
|
-
|
53
|
+
mime-types (3.3.1)
|
54
|
+
mime-types-data (~> 3.2015)
|
55
|
+
mime-types-data (3.2021.0704)
|
56
|
+
minitest (5.15.0)
|
57
|
+
multi_test (0.1.2)
|
20
58
|
rake (10.5.0)
|
21
|
-
|
22
|
-
|
23
|
-
|
59
|
+
sys-uname (1.2.2)
|
60
|
+
ffi (~> 1.1)
|
61
|
+
tzinfo (2.0.4)
|
62
|
+
concurrent-ruby (~> 1.0)
|
24
63
|
|
25
64
|
PLATFORMS
|
26
65
|
ruby
|
@@ -28,6 +67,7 @@ PLATFORMS
|
|
28
67
|
DEPENDENCIES
|
29
68
|
active_period!
|
30
69
|
bundler (~> 2.0)
|
70
|
+
cucumber
|
31
71
|
rake (~> 10.0)
|
32
72
|
|
33
73
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -51,6 +51,9 @@ Period.new(..Time.now).months.reverse_each # => Enumerable
|
|
51
51
|
# Write a date for me (I18n supported)
|
52
52
|
Period.new('20/01/2017'...'20/01/2021').to_s
|
53
53
|
=> "From the 20 January 2017 to the 20 January 2021 excluded"
|
54
|
+
|
55
|
+
# Get all US holidays in the next week (see holiday's section below)
|
56
|
+
Period.next_week.holidays(:us)
|
54
57
|
```
|
55
58
|
|
56
59
|
## Detailed view
|
@@ -311,7 +314,7 @@ For a FreePeriod or if you need to print the start and the end of your period di
|
|
311
314
|
## The tricky case of Weeks
|
312
315
|
|
313
316
|
Weeks are implemented following the [ISO 8601](https://en.wikipedia.org/wiki/ISO_week_date)
|
314
|
-
So `Period.this_month.weeks.first` doesn't necessarily include the first days of the month
|
317
|
+
So `Period.this_month.weeks.first` doesn't necessarily include the first days of the month
|
315
318
|
Also a **StandardPeriod** and a **FreePeriod** covering the same range of time, may not includes the same `Weeks`
|
316
319
|
|
317
320
|
## TimeZone
|
@@ -333,30 +336,31 @@ require 'holidays'
|
|
333
336
|
# Get all worldwide holidays in the current month
|
334
337
|
Period.this_month.holidays
|
335
338
|
|
336
|
-
# Get all US holidays in the
|
337
|
-
Period.
|
339
|
+
# Get all US holidays in the next week
|
340
|
+
Period.next_week.holidays(:us)
|
338
341
|
|
339
|
-
# Get all US and CA holidays in the
|
340
|
-
Period.
|
342
|
+
# Get all US and CA holidays in the prev quarter
|
343
|
+
Period.prev_quarter.holidays(:us, :ca)
|
341
344
|
|
342
345
|
# First up coming `FR` holiday
|
343
|
-
holiday =
|
344
|
-
# return the next holiday
|
346
|
+
holiday = (Time.now..).to_period.holidays(:fr).first
|
347
|
+
# return the next holiday with same options as the original `.holidays` collection
|
345
348
|
holiday.next
|
346
|
-
# return the previous holiday
|
349
|
+
# return the previous holiday with same options as the original `.holidays` collection
|
347
350
|
holiday.prev
|
348
351
|
```
|
349
352
|
|
350
|
-
:warning:
|
353
|
+
:warning: If you call a `holidays` related method without the [gem holidays](https://github.com/holidays/holidays) in your project
|
354
|
+
You will raise a `RuntimeError`
|
351
355
|
```ruby
|
352
356
|
Period.this_month.holidays
|
353
357
|
#=> RuntimeError (The gem "holidays" is needed for this feature to work)
|
354
358
|
```
|
355
359
|
|
356
|
-
## Planned updates
|
360
|
+
## Planned updates & Idea
|
357
361
|
|
358
362
|
- [ ] ActiveRecord Serializer (maybe)
|
359
|
-
- [ ]
|
363
|
+
- [ ] Dedicated Exception for each possible error
|
360
364
|
|
361
365
|
## Bug reports
|
362
366
|
|
data/active_period.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
|
10
10
|
spec.summary = 'Manage time ranges without brain damage.'
|
11
11
|
# spec.description = "Period.new('01/01/2020'..Time.now)"
|
12
|
-
spec.homepage = "https://github.com/billaul/
|
12
|
+
spec.homepage = "https://github.com/billaul/active_period"
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -37,8 +37,11 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.require_paths = %w[lib config]
|
38
38
|
|
39
39
|
spec.required_ruby_version = '>= 2.7'
|
40
|
-
|
40
|
+
|
41
|
+
spec.add_runtime_dependency 'activesupport', '>= 5', '~> 7'
|
41
42
|
spec.add_runtime_dependency 'i18n', '~> 1'
|
43
|
+
|
42
44
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
43
45
|
spec.add_development_dependency 'rake', '~> 10.0'
|
46
|
+
spec.add_development_dependency 'cucumber'
|
44
47
|
end
|
data/lib/active_period.rb
CHANGED
data/lib/period.rb
CHANGED
@@ -1,34 +1,43 @@
|
|
1
|
+
# This module is intended to hide the complexity of ActivePeriod
|
2
|
+
# And permit the user to write less and doing more
|
1
3
|
module Period
|
2
|
-
|
3
|
-
|
4
|
+
|
5
|
+
# Shorthand to ActivePeriod::FreePeriod.new
|
6
|
+
def self.new(range, allow_beginless: true, allow_endless: true)
|
7
|
+
ActivePeriod::FreePeriod.new(range, allow_beginless: allow_beginless, allow_endless: allow_endless)
|
4
8
|
end
|
5
9
|
|
10
|
+
# Shorthand ActivePeriod::FreePeriod.new(range, allow_beginless: false, allow_endless: false)
|
6
11
|
def self.bounded(range)
|
7
12
|
ActivePeriod::FreePeriod.new(range, allow_beginless: false, allow_endless: false)
|
8
13
|
end
|
9
14
|
|
15
|
+
# env_time provide a Fallback if the project dont specify any Time.zone
|
10
16
|
def self.env_time
|
11
17
|
(Time.zone || Time)
|
12
18
|
end
|
13
19
|
|
20
|
+
# Dynamic definition of `.(last|this|next)_(day|week|month|quarter|year)`
|
21
|
+
# and `.yesterday` `.today` `.tomorrow`
|
22
|
+
# TODO implement (last|next)_holiday
|
14
23
|
class << self
|
15
|
-
%i[day week month quarter year].each do |
|
16
|
-
define_method "last_#{
|
17
|
-
date = env_time.now.send(
|
18
|
-
Object.const_get("ActivePeriod::#{
|
24
|
+
%i[day week month quarter year].each do |standard_period|
|
25
|
+
define_method "last_#{standard_period}" do
|
26
|
+
date = env_time.now.send(standard_period == :day ? 'yesterday' : "last_#{standard_period}")
|
27
|
+
Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(date)
|
19
28
|
end
|
20
29
|
|
21
|
-
define_method "this_#{
|
22
|
-
Object.const_get("ActivePeriod::#{
|
30
|
+
define_method "this_#{standard_period}" do
|
31
|
+
Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(env_time.now)
|
23
32
|
end
|
24
33
|
|
25
|
-
define_method "next_#{
|
26
|
-
date = env_time.now.send(
|
27
|
-
Object.const_get("ActivePeriod::#{
|
34
|
+
define_method "next_#{standard_period}" do
|
35
|
+
date = env_time.now.send(standard_period == :day ? 'tomorrow' : "next_#{standard_period}")
|
36
|
+
Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(date)
|
28
37
|
end
|
29
38
|
|
30
|
-
define_method
|
31
|
-
Object.const_get("ActivePeriod::#{
|
39
|
+
define_method standard_period.to_s do |range|
|
40
|
+
Object.const_get("ActivePeriod::#{standard_period.capitalize}").new(range)
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
@@ -36,6 +45,10 @@ module Period
|
|
36
45
|
alias tomorrow next_day
|
37
46
|
alias today this_day
|
38
47
|
|
48
|
+
# Experimental non-documented feature
|
49
|
+
# Inpired form ActiveRecord dynamic find_by_x like User.find_by_name
|
50
|
+
# Example: Period.last_3_weeks_from_now == Period.mew(2.weeks.ago.beginning_of_week..Time.now.end_of_week)
|
51
|
+
# Note : Maybe it should return a collection of StandardPeriod
|
39
52
|
def method_missing(method_name, *arguments, &block)
|
40
53
|
super unless method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/)
|
41
54
|
last_next, count, klass = method_name.to_s.split('_')
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_period
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- billau_l
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5'
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5'
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: i18n
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +72,20 @@ dependencies:
|
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: cucumber
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
69
89
|
description:
|
70
90
|
email:
|
71
91
|
executables: []
|
@@ -115,14 +135,14 @@ files:
|
|
115
135
|
- lib/numeric.rb
|
116
136
|
- lib/period.rb
|
117
137
|
- lib/range.rb
|
118
|
-
homepage: https://github.com/billaul/
|
138
|
+
homepage: https://github.com/billaul/active_period
|
119
139
|
licenses:
|
120
140
|
- MIT
|
121
141
|
metadata:
|
122
|
-
bug_tracker_uri: https://github.com/billaul/
|
123
|
-
homepage_uri: https://github.com/billaul/
|
124
|
-
documentation_uri: https://github.com/billaul/
|
125
|
-
source_code_uri: https://github.com/billaul/
|
142
|
+
bug_tracker_uri: https://github.com/billaul/active_period/issues
|
143
|
+
homepage_uri: https://github.com/billaul/active_period
|
144
|
+
documentation_uri: https://github.com/billaul/active_period
|
145
|
+
source_code_uri: https://github.com/billaul/active_period
|
126
146
|
post_install_message:
|
127
147
|
rdoc_options: []
|
128
148
|
require_paths:
|