active_period 7.1.1 → 7.1.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 -5
- data/config/locales/fr.yml +2 -2
- data/lib/active_period/version.rb +1 -1
- data/lib/period.rb +31 -7
- 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: e197dc4558fd215fc7090f5a14ad074e769457abfa7665b4b2393e5ba2a23d52
|
4
|
+
data.tar.gz: 54c3de6172706d0f08e2885b6401b3f1c964526498193a63c13af4fbfab6eb99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a228d61ffcb56d1f9206127e22775e2a3ec109822ce0b8242e6e778d8edb08531dd9b2834cc7def80cb42ec7cf148b2abc8776059228c5fb7b7d9cb90ec68562
|
7
|
+
data.tar.gz: 25550cbd55706774bfd34e68690be5d39b2e01b6681f33b3134d3c7169949c9e1d017ac40cadd24d041eef2c85d3ce6c05dbb8fe76761d6a2fabebe501230e24
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_period (7.1.
|
5
|
-
activesupport (>= 5,
|
4
|
+
active_period (7.1.1)
|
5
|
+
activesupport (>= 5, < 8)
|
6
6
|
i18n (~> 1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (
|
11
|
+
activesupport (7.0.4)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
15
15
|
tzinfo (~> 2.0)
|
16
|
-
zeitwerk (~> 2.3)
|
17
16
|
builder (3.2.4)
|
18
17
|
concurrent-ruby (1.1.10)
|
19
18
|
cucumber (7.0.0)
|
@@ -61,7 +60,6 @@ GEM
|
|
61
60
|
ffi (~> 1.1)
|
62
61
|
tzinfo (2.0.5)
|
63
62
|
concurrent-ruby (~> 1.0)
|
64
|
-
zeitwerk (2.6.0)
|
65
63
|
|
66
64
|
PLATFORMS
|
67
65
|
ruby
|
data/config/locales/fr.yml
CHANGED
@@ -15,8 +15,8 @@ fr:
|
|
15
15
|
param_must_be_a_range: Le paramètre doit hériter de la class Range
|
16
16
|
free_period:
|
17
17
|
default_format: Du %{from} au %{to} %{ending}
|
18
|
-
beginless_format: Jusqu'au %{
|
19
|
-
endless_format: Depuis le %{
|
18
|
+
beginless_format: Jusqu'au %{to} %{ending}
|
19
|
+
endless_format: Depuis le %{from}
|
20
20
|
boundless_format: Sans limite de temps
|
21
21
|
standard_period:
|
22
22
|
base_class_is_abstract: StandardPeriod est une class abstraite qui ne doit pas être utiliser directement
|
data/lib/period.rb
CHANGED
@@ -50,32 +50,56 @@ module Period
|
|
50
50
|
alias tomorrow next_day
|
51
51
|
alias today this_day
|
52
52
|
|
53
|
-
|
53
|
+
LAST_OR_NEXT_REGEX = /^(:?last|next)_(\d+)_(day|week|month|quarter|year)s?(_from_now)?$/
|
54
|
+
LAST_AND_NEXT_REGEX = /^last_(\d+)_(day|week|month|quarter|year)s?_to_next_(\d+)_(day|week|month|quarter|year)s?$/
|
55
|
+
|
56
|
+
# Experimenta l non-documented feature
|
54
57
|
# Inpired form ActiveRecord dynamic find_by_x like User.find_by_name
|
55
58
|
# Example: Period.last_3_weeks_from_now == Period.mew(2.weeks.ago.beginning_of_week..Time.now.end_of_week)
|
56
|
-
# Note : Maybe it should return a collection of StandardPeriod
|
57
59
|
def method_missing(method_name, *arguments, &block)
|
58
|
-
|
59
|
-
|
60
|
+
if method_name.match? LAST_OR_NEXT_REGEX
|
61
|
+
missing_last_or_next(method_name)
|
62
|
+
elsif method_name.match? LAST_AND_NEXT_REGEX
|
63
|
+
missing_last_and_next(method_name)
|
64
|
+
else
|
65
|
+
super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def missing_last_or_next(method_name)
|
70
|
+
last_next, count, klass, from_now = method_name.to_s.scan(LAST_OR_NEXT_REGEX).flatten
|
60
71
|
klass = klass.singularize
|
61
72
|
|
62
73
|
case last_next
|
63
74
|
when 'last'
|
64
75
|
from = count.to_i.send(klass).ago.send("beginning_of_#{klass}")
|
65
76
|
to = env_time.now
|
66
|
-
to -= 1.send(klass) unless
|
77
|
+
to -= 1.send(klass) unless from_now
|
67
78
|
to = to.send("end_of_#{klass}")
|
68
79
|
when 'next'
|
69
80
|
from = env_time.now
|
70
|
-
from += 1.send(klass) unless
|
81
|
+
from += 1.send(klass) unless from_now
|
71
82
|
from = from.send("beginning_of_#{klass}")
|
72
83
|
to = count.to_i.send(klass).from_now.send("end_of_#{klass}")
|
73
84
|
end
|
74
85
|
self.new(from..to)
|
75
86
|
end
|
76
87
|
|
88
|
+
def missing_last_and_next(method_name)
|
89
|
+
last_count, last_klass, next_count, next_klass = method_name.to_s.scan(LAST_AND_NEXT_REGEX).flatten
|
90
|
+
last_klass = last_klass.singularize
|
91
|
+
next_klass = next_klass.singularize
|
92
|
+
|
93
|
+
from = last_count.to_i.send(last_klass).ago.send("beginning_of_#{last_klass}")
|
94
|
+
to = next_count.to_i.send(next_klass).from_now.send("end_of_#{next_klass}")
|
95
|
+
|
96
|
+
self.new(from..to)
|
97
|
+
end
|
98
|
+
|
77
99
|
def respond_to_missing?(method_name, include_private = false)
|
78
|
-
method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/) ||
|
100
|
+
method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/) ||
|
101
|
+
method_name.match?(/(last)_\d+_(day|week|month|quarter|year)s?_to_next_\d+_(day|week|month|quarter|year)s?/ ) ||
|
102
|
+
super
|
79
103
|
end
|
80
104
|
end
|
81
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_period
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.2
|
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: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.3.22
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Manage time ranges without brain damage.
|