i18n_date_range 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +3 -3
- data/README.md +7 -2
- data/config/locales/en-GB.yml +155 -17
- data/config/locales/en.yml +155 -17
- data/config/locales/fr.yml +155 -17
- data/lib/i18n_date_range/i18n_date_range_generator.rb +59 -27
- data/lib/i18n_date_range/i18n_date_range_helper.rb +3 -2
- data/lib/i18n_date_range/version.rb +1 -1
- 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: 4b5b37d47192e7ed082d17c10cb9e633b3267699985ceb4a9d5f23914d477f16
|
4
|
+
data.tar.gz: ab2eacf2fe9807d9e305f52c626a40352d2a445e0872c03ffe403b80aa84a884
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a2ac59f09a6ac60221430eb270505b886beb3fd13cb335f7da7b174b7d283a8cf899d232572428048e903757958889bd442ca2f2eb8246dbaaf9915e7ceee0d
|
7
|
+
data.tar.gz: cbb79ad4ca1cac1a7058c9909e394ea6bc11424d1487798350275c53a706e7bfd771ef3ccf2bb9e8ae413ad99f16886bc8d0e9e1de301e70d1dd3e89b8e04a4f
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
i18n_date_range (1.0.
|
4
|
+
i18n_date_range (1.0.3)
|
5
5
|
rails
|
6
6
|
rails-i18n
|
7
7
|
|
@@ -119,7 +119,7 @@ GEM
|
|
119
119
|
mini_mime (1.1.5)
|
120
120
|
minitest (5.20.0)
|
121
121
|
mutex_m (0.1.2)
|
122
|
-
net-imap (0.
|
122
|
+
net-imap (0.3.7)
|
123
123
|
date
|
124
124
|
net-protocol
|
125
125
|
net-pop (0.1.2)
|
@@ -255,4 +255,4 @@ DEPENDENCIES
|
|
255
255
|
rubocop-rails
|
256
256
|
|
257
257
|
BUNDLED WITH
|
258
|
-
2.4.
|
258
|
+
2.4.21
|
data/README.md
CHANGED
@@ -19,13 +19,18 @@ And then execute:
|
|
19
19
|
This gem comes with an integrated view helper: `date_range_i18n` which takes 3 parameters:
|
20
20
|
- date_from
|
21
21
|
- date_to (optional)
|
22
|
-
-
|
22
|
+
- a hash of additional formatting options(optional)
|
23
23
|
|
24
|
-
|
24
|
+
The options hash currently support 2 arguments:
|
25
|
+
- format: can be `:short` or `:long` (default is :short)
|
26
|
+
- layout: can be `:one_line`or `:two_lines` (default is :one_line)
|
25
27
|
|
26
28
|
"Short" format means without the explicit day name (September 8, 2024).
|
27
29
|
"Long" format means with it (Friday, September 8, 2024).
|
28
30
|
|
31
|
+
"One line" layout means the string will be displayed on one line only (From September 8, 2024 to September 8, 2025)
|
32
|
+
"Two lines" layout means the result will be displayed on 2 lines,separated with `<br>` (September 8, 2024<br>September 8, 2025)
|
33
|
+
|
29
34
|
## Change texts or formats
|
30
35
|
|
31
36
|
This gem is based on I18n. Feel free to overwrite any key you want.
|
data/config/locales/en-GB.yml
CHANGED
@@ -1,19 +1,157 @@
|
|
1
1
|
en-GB:
|
2
2
|
date_range:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
no_end:
|
4
|
+
one_line:
|
5
|
+
short:
|
6
|
+
from:
|
7
|
+
sentence: "From %-d %B %Y"
|
8
|
+
upcase_first: false
|
9
|
+
to:
|
10
|
+
sentence: ""
|
11
|
+
upcase_first: false
|
12
|
+
long:
|
13
|
+
from:
|
14
|
+
sentence: "From %A %-d %B %Y"
|
15
|
+
upcase_first: false
|
16
|
+
to:
|
17
|
+
sentence: ""
|
18
|
+
upcase_first: false
|
19
|
+
two_lines:
|
20
|
+
short:
|
21
|
+
from:
|
22
|
+
sentence: "%-d %B %Y"
|
23
|
+
upcase_first: false
|
24
|
+
to:
|
25
|
+
sentence: ""
|
26
|
+
upcase_first: false
|
27
|
+
long:
|
28
|
+
from:
|
29
|
+
sentence: "%A %-d %B %Y"
|
30
|
+
upcase_first: true
|
31
|
+
to:
|
32
|
+
sentence: ""
|
33
|
+
upcase_first: false
|
34
|
+
same_day:
|
35
|
+
one_line:
|
36
|
+
short:
|
37
|
+
from:
|
38
|
+
sentence: "%-d %B %Y"
|
39
|
+
upcase_first: false
|
40
|
+
to:
|
41
|
+
sentence: ""
|
42
|
+
upcase_first: false
|
43
|
+
long:
|
44
|
+
from:
|
45
|
+
sentence: "%A %-d %B %Y"
|
46
|
+
upcase_first: true
|
47
|
+
to:
|
48
|
+
sentence: ""
|
49
|
+
upcase_first: false
|
50
|
+
two_lines:
|
51
|
+
short:
|
52
|
+
from:
|
53
|
+
sentence: "%-d %B %Y"
|
54
|
+
upcase_first: false
|
55
|
+
to:
|
56
|
+
sentence: ""
|
57
|
+
upcase_first: false
|
58
|
+
long:
|
59
|
+
from:
|
60
|
+
sentence: "%A %-d %B %Y"
|
61
|
+
upcase_first: true
|
62
|
+
to:
|
63
|
+
sentence: ""
|
64
|
+
upcase_first: false
|
65
|
+
same_month:
|
66
|
+
one_line:
|
67
|
+
short:
|
68
|
+
from:
|
69
|
+
sentence: "From %-d"
|
70
|
+
upcase_first: false
|
71
|
+
to:
|
72
|
+
sentence: " to %-d %B %Y"
|
73
|
+
upcase_first: false
|
74
|
+
long:
|
75
|
+
from:
|
76
|
+
sentence: "From %A %-d"
|
77
|
+
upcase_first: false
|
78
|
+
to:
|
79
|
+
sentence: " to %A %-d %B %Y"
|
80
|
+
upcase_first: false
|
81
|
+
two_lines:
|
82
|
+
short:
|
83
|
+
from:
|
84
|
+
sentence: "%-d %B"
|
85
|
+
upcase_first: false
|
86
|
+
to:
|
87
|
+
sentence: "%-d %B %Y"
|
88
|
+
upcase_first: false
|
89
|
+
long:
|
90
|
+
from:
|
91
|
+
sentence: "%A %-d %B"
|
92
|
+
upcase_first: true
|
93
|
+
to:
|
94
|
+
sentence: "%A %-d %B %Y"
|
95
|
+
upcase_first: true
|
96
|
+
same_year:
|
97
|
+
one_line:
|
98
|
+
short:
|
99
|
+
from:
|
100
|
+
sentence: "From %-d %B"
|
101
|
+
upcase_first: false
|
102
|
+
to:
|
103
|
+
sentence: " to %-d %B %Y"
|
104
|
+
upcase_first: false
|
105
|
+
long:
|
106
|
+
from:
|
107
|
+
sentence: "From %A %-d %B"
|
108
|
+
upcase_first: false
|
109
|
+
to:
|
110
|
+
sentence: " to %A %-d %B %Y"
|
111
|
+
upcase_first: false
|
112
|
+
two_lines:
|
113
|
+
short:
|
114
|
+
from:
|
115
|
+
sentence: "%-d %B"
|
116
|
+
upcase_first: false
|
117
|
+
to:
|
118
|
+
sentence: "%-d %B %Y"
|
119
|
+
upcase_first: false
|
120
|
+
long:
|
121
|
+
from:
|
122
|
+
sentence: "%A %-d %B"
|
123
|
+
upcase_first: true
|
124
|
+
to:
|
125
|
+
sentence: "%A %-d %B %Y"
|
126
|
+
upcase_first: true
|
127
|
+
other:
|
128
|
+
one_line:
|
129
|
+
short:
|
130
|
+
from:
|
131
|
+
sentence: "From %-d %B %Y"
|
132
|
+
upcase_first: false
|
133
|
+
to:
|
134
|
+
sentence: " to %-d %B %Y"
|
135
|
+
upcase_first: false
|
136
|
+
long:
|
137
|
+
from:
|
138
|
+
sentence: "From %A %-d %B %Y"
|
139
|
+
upcase_first: false
|
140
|
+
to:
|
141
|
+
sentence: " to %A %-d %B %Y"
|
142
|
+
upcase_first: false
|
143
|
+
two_lines:
|
144
|
+
short:
|
145
|
+
from:
|
146
|
+
sentence: "%-d %B %Y"
|
147
|
+
upcase_first: false
|
148
|
+
to:
|
149
|
+
sentence: "%-d %B %Y"
|
150
|
+
upcase_first: false
|
151
|
+
long:
|
152
|
+
from:
|
153
|
+
sentence: "%A %-d %B %Y"
|
154
|
+
upcase_first: true
|
155
|
+
to:
|
156
|
+
sentence: "%A %-d %B %Y"
|
157
|
+
upcase_first: true
|
data/config/locales/en.yml
CHANGED
@@ -1,19 +1,157 @@
|
|
1
1
|
en:
|
2
2
|
date_range:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
no_end:
|
4
|
+
one_line:
|
5
|
+
short:
|
6
|
+
from:
|
7
|
+
sentence: "From %B %-d, %Y"
|
8
|
+
upcase_first: false
|
9
|
+
to:
|
10
|
+
sentence: ""
|
11
|
+
upcase_first: false
|
12
|
+
long:
|
13
|
+
from:
|
14
|
+
sentence: "From %A %B %-d, %Y"
|
15
|
+
upcase_first: false
|
16
|
+
to:
|
17
|
+
sentence: ""
|
18
|
+
upcase_first: false
|
19
|
+
two_lines:
|
20
|
+
short:
|
21
|
+
from:
|
22
|
+
sentence: "%B %-d, %Y"
|
23
|
+
upcase_first: true
|
24
|
+
to:
|
25
|
+
sentence: ""
|
26
|
+
upcase_first: false
|
27
|
+
long:
|
28
|
+
from:
|
29
|
+
sentence: "%A %B %-d, %Y"
|
30
|
+
upcase_first: true
|
31
|
+
to:
|
32
|
+
sentence: ""
|
33
|
+
upcase_first: false
|
34
|
+
same_day:
|
35
|
+
one_line:
|
36
|
+
short:
|
37
|
+
from:
|
38
|
+
sentence: "%B %-d, %Y"
|
39
|
+
upcase_first: true
|
40
|
+
to:
|
41
|
+
sentence: ""
|
42
|
+
upcase_first: false
|
43
|
+
long:
|
44
|
+
from:
|
45
|
+
sentence: "%A %B %-d, %Y"
|
46
|
+
upcase_first: true
|
47
|
+
to:
|
48
|
+
sentence: ""
|
49
|
+
upcase_first: false
|
50
|
+
two_lines:
|
51
|
+
short:
|
52
|
+
from:
|
53
|
+
sentence: "%B %-d, %Y"
|
54
|
+
upcase_first: true
|
55
|
+
to:
|
56
|
+
sentence: ""
|
57
|
+
upcase_first: false
|
58
|
+
long:
|
59
|
+
from:
|
60
|
+
sentence: "%A %B %-d, %Y"
|
61
|
+
upcase_first: true
|
62
|
+
to:
|
63
|
+
sentence: ""
|
64
|
+
upcase_first: false
|
65
|
+
same_month:
|
66
|
+
one_line:
|
67
|
+
short:
|
68
|
+
from:
|
69
|
+
sentence: "From %B %-d"
|
70
|
+
upcase_first: false
|
71
|
+
to:
|
72
|
+
sentence: " to %-d, %Y"
|
73
|
+
upcase_first: false
|
74
|
+
long:
|
75
|
+
from:
|
76
|
+
sentence: "From %A %B %-d"
|
77
|
+
upcase_first: false
|
78
|
+
to:
|
79
|
+
sentence: " to %A %B %-d, %Y"
|
80
|
+
upcase_first: false
|
81
|
+
two_lines:
|
82
|
+
short:
|
83
|
+
from:
|
84
|
+
sentence: "%B %-d"
|
85
|
+
upcase_first: true
|
86
|
+
to:
|
87
|
+
sentence: "%B %-d, %Y"
|
88
|
+
upcase_first: true
|
89
|
+
long:
|
90
|
+
from:
|
91
|
+
sentence: "%A %B %-d"
|
92
|
+
upcase_first: true
|
93
|
+
to:
|
94
|
+
sentence: "%A %B %-d, %Y"
|
95
|
+
upcase_first: true
|
96
|
+
same_year:
|
97
|
+
one_line:
|
98
|
+
short:
|
99
|
+
from:
|
100
|
+
sentence: "From %B %-d"
|
101
|
+
upcase_first: false
|
102
|
+
to:
|
103
|
+
sentence: " to %B %-d, %Y"
|
104
|
+
upcase_first: false
|
105
|
+
long:
|
106
|
+
from:
|
107
|
+
sentence: "From %A %B %-d"
|
108
|
+
upcase_first: false
|
109
|
+
to:
|
110
|
+
sentence: " to %A %B %-d, %Y"
|
111
|
+
upcase_first: false
|
112
|
+
two_lines:
|
113
|
+
short:
|
114
|
+
from:
|
115
|
+
sentence: "%B %-d"
|
116
|
+
upcase_first: true
|
117
|
+
to:
|
118
|
+
sentence: "%B %-d, %Y"
|
119
|
+
upcase_first: true
|
120
|
+
long:
|
121
|
+
from:
|
122
|
+
sentence: "%A %B %-d"
|
123
|
+
upcase_first: true
|
124
|
+
to:
|
125
|
+
sentence: "%A %B %-d, %Y"
|
126
|
+
upcase_first: true
|
127
|
+
other:
|
128
|
+
one_line:
|
129
|
+
short:
|
130
|
+
from:
|
131
|
+
sentence: "From %B %-d, %Y"
|
132
|
+
upcase_first: false
|
133
|
+
to:
|
134
|
+
sentence: " to %B %-d, %Y"
|
135
|
+
upcase_first: false
|
136
|
+
long:
|
137
|
+
from:
|
138
|
+
sentence: "From %A %B %-d, %Y"
|
139
|
+
upcase_first: false
|
140
|
+
to:
|
141
|
+
sentence: " to %A %B %-d, %Y"
|
142
|
+
upcase_first: false
|
143
|
+
two_lines:
|
144
|
+
short:
|
145
|
+
from:
|
146
|
+
sentence: "%B %-d, %Y"
|
147
|
+
upcase_first: true
|
148
|
+
to:
|
149
|
+
sentence: "%B %-d, %Y"
|
150
|
+
upcase_first: true
|
151
|
+
long:
|
152
|
+
from:
|
153
|
+
sentence: "%A %B %-d, %Y"
|
154
|
+
upcase_first: true
|
155
|
+
to:
|
156
|
+
sentence: "%A %B %-d, %Y"
|
157
|
+
upcase_first: true
|
data/config/locales/fr.yml
CHANGED
@@ -1,19 +1,157 @@
|
|
1
1
|
fr:
|
2
2
|
date_range:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
no_end:
|
4
|
+
one_line:
|
5
|
+
short:
|
6
|
+
from:
|
7
|
+
sentence: "À partir du %-d %B %Y"
|
8
|
+
upcase_first: false
|
9
|
+
to:
|
10
|
+
sentence: ""
|
11
|
+
upcase_first: false
|
12
|
+
long:
|
13
|
+
from:
|
14
|
+
sentence: "À partir du %A %-d %B %Y"
|
15
|
+
upcase_first: false
|
16
|
+
to:
|
17
|
+
sentence: ""
|
18
|
+
upcase_first: false
|
19
|
+
two_lines:
|
20
|
+
short:
|
21
|
+
from:
|
22
|
+
sentence: "%-d %B %Y"
|
23
|
+
upcase_first: false
|
24
|
+
to:
|
25
|
+
sentence: ""
|
26
|
+
upcase_first: false
|
27
|
+
long:
|
28
|
+
from:
|
29
|
+
sentence: "%A %-d %B %Y"
|
30
|
+
upcase_first: true
|
31
|
+
to:
|
32
|
+
sentence: ""
|
33
|
+
upcase_first: false
|
34
|
+
same_day:
|
35
|
+
one_line:
|
36
|
+
short:
|
37
|
+
from:
|
38
|
+
sentence: "%-d %B %Y"
|
39
|
+
upcase_first: false
|
40
|
+
to:
|
41
|
+
sentence: ""
|
42
|
+
upcase_first: false
|
43
|
+
long:
|
44
|
+
from:
|
45
|
+
sentence: "%A %-d %B %Y"
|
46
|
+
upcase_first: true
|
47
|
+
to:
|
48
|
+
sentence: ""
|
49
|
+
upcase_first: false
|
50
|
+
two_lines:
|
51
|
+
short:
|
52
|
+
from:
|
53
|
+
sentence: "%-d %B %Y"
|
54
|
+
upcase_first: false
|
55
|
+
to:
|
56
|
+
sentence: ""
|
57
|
+
upcase_first: false
|
58
|
+
long:
|
59
|
+
from:
|
60
|
+
sentence: "%A %-d %B %Y"
|
61
|
+
upcase_first: true
|
62
|
+
to:
|
63
|
+
sentence: ""
|
64
|
+
upcase_first: false
|
65
|
+
same_month:
|
66
|
+
one_line:
|
67
|
+
short:
|
68
|
+
from:
|
69
|
+
sentence: "Du %-d"
|
70
|
+
upcase_first: false
|
71
|
+
to:
|
72
|
+
sentence: " au %-d %B %Y"
|
73
|
+
upcase_first: false
|
74
|
+
long:
|
75
|
+
from:
|
76
|
+
sentence: "Du %A %-d"
|
77
|
+
upcase_first: false
|
78
|
+
to:
|
79
|
+
sentence: " au %A %-d %B %Y"
|
80
|
+
upcase_first: false
|
81
|
+
two_lines:
|
82
|
+
short:
|
83
|
+
from:
|
84
|
+
sentence: "%-d %B"
|
85
|
+
upcase_first: false
|
86
|
+
to:
|
87
|
+
sentence: "%-d %B %Y"
|
88
|
+
upcase_first: false
|
89
|
+
long:
|
90
|
+
from:
|
91
|
+
sentence: "%A %-d %B"
|
92
|
+
upcase_first: true
|
93
|
+
to:
|
94
|
+
sentence: "%A %-d %B %Y"
|
95
|
+
upcase_first: true
|
96
|
+
same_year:
|
97
|
+
one_line:
|
98
|
+
short:
|
99
|
+
from:
|
100
|
+
sentence: "Du %-d %B"
|
101
|
+
upcase_first: false
|
102
|
+
to:
|
103
|
+
sentence: " au %-d %B %Y"
|
104
|
+
upcase_first: false
|
105
|
+
long:
|
106
|
+
from:
|
107
|
+
sentence: "Du %A %-d %B"
|
108
|
+
upcase_first: false
|
109
|
+
to:
|
110
|
+
sentence: " au %A %-d %B %Y"
|
111
|
+
upcase_first: false
|
112
|
+
two_lines:
|
113
|
+
short:
|
114
|
+
from:
|
115
|
+
sentence: "%-d %B"
|
116
|
+
upcase_first: false
|
117
|
+
to:
|
118
|
+
sentence: "%-d %B %Y"
|
119
|
+
upcase_first: false
|
120
|
+
long:
|
121
|
+
from:
|
122
|
+
sentence: "%A %-d %B"
|
123
|
+
upcase_first: true
|
124
|
+
to:
|
125
|
+
sentence: "%A %-d %B %Y"
|
126
|
+
upcase_first: true
|
127
|
+
other:
|
128
|
+
one_line:
|
129
|
+
short:
|
130
|
+
from:
|
131
|
+
sentence: "Du %-d %B %Y"
|
132
|
+
upcase_first: false
|
133
|
+
to:
|
134
|
+
sentence: " au %-d %B %Y"
|
135
|
+
upcase_first: false
|
136
|
+
long:
|
137
|
+
from:
|
138
|
+
sentence: "Du %A %-d %B %Y"
|
139
|
+
upcase_first: false
|
140
|
+
to:
|
141
|
+
sentence: " au %A %-d %B %Y"
|
142
|
+
upcase_first: false
|
143
|
+
two_lines:
|
144
|
+
short:
|
145
|
+
from:
|
146
|
+
sentence: "%-d %B %Y"
|
147
|
+
upcase_first: false
|
148
|
+
to:
|
149
|
+
sentence: "%-d %B %Y"
|
150
|
+
upcase_first: false
|
151
|
+
long:
|
152
|
+
from:
|
153
|
+
sentence: "%A %-d %B %Y"
|
154
|
+
upcase_first: true
|
155
|
+
to:
|
156
|
+
sentence: "%A %-d %B %Y"
|
157
|
+
upcase_first: true
|
@@ -4,6 +4,13 @@
|
|
4
4
|
class I18nDateRangeGenerator
|
5
5
|
attr_reader :from_date, :to_date, :format, :layout
|
6
6
|
|
7
|
+
KIND_NO_END = :no_end
|
8
|
+
KIND_SAME_DAY = :same_day
|
9
|
+
KIND_SAME_MONTH = :same_month
|
10
|
+
KIND_SAME_YEAR = :same_year
|
11
|
+
KIND_OTHER = :other
|
12
|
+
|
13
|
+
# "format" can be :short or :long. "layout" can be :one_line or :two_lines
|
7
14
|
def initialize(from_date, to_date = nil, format: :short, layout: :one_line)
|
8
15
|
@from_date = from_date
|
9
16
|
@to_date = to_date
|
@@ -12,50 +19,75 @@ class I18nDateRangeGenerator
|
|
12
19
|
end
|
13
20
|
|
14
21
|
def to_s
|
15
|
-
|
22
|
+
layout == :two_lines && to_formatted.present? ? from_formatted + '<br>' + to_formatted : from_formatted + to_formatted
|
16
23
|
end
|
17
24
|
|
18
25
|
protected
|
19
26
|
|
20
|
-
|
27
|
+
# Analyzing
|
28
|
+
|
29
|
+
def kind
|
30
|
+
unless @kind
|
31
|
+
@kind = KIND_OTHER
|
32
|
+
@kind = KIND_SAME_YEAR if same_year?
|
33
|
+
@kind = KIND_SAME_MONTH if same_month?
|
34
|
+
@kind = KIND_SAME_DAY if same_day?
|
35
|
+
@kind = KIND_NO_END if no_end?
|
36
|
+
end
|
37
|
+
@kind
|
38
|
+
end
|
39
|
+
|
40
|
+
def same_year?
|
41
|
+
from_date.year == to_date&.year
|
42
|
+
end
|
43
|
+
|
44
|
+
def same_month?
|
45
|
+
from_date.year == to_date&.year && from_date.month == to_date&.month
|
46
|
+
end
|
47
|
+
|
48
|
+
def same_day?
|
21
49
|
to_date == from_date
|
22
50
|
end
|
23
51
|
|
24
|
-
def
|
25
|
-
|
26
|
-
"date_range.#{layout}.without_to",
|
27
|
-
from: format_date(from_date, :day_month_year)
|
28
|
-
).capitalize
|
52
|
+
def no_end?
|
53
|
+
to_date.blank?
|
29
54
|
end
|
30
55
|
|
31
|
-
def
|
32
|
-
I18n.t(
|
33
|
-
"date_range.#{layout}.with_to",
|
34
|
-
from: format_date(from_date, from_format),
|
35
|
-
to: format_date(to_date, :day_month_year)
|
36
|
-
).capitalize
|
56
|
+
def from_sentence
|
57
|
+
I18n.t("#{composite_key}.from.sentence")
|
37
58
|
end
|
38
59
|
|
39
|
-
def
|
40
|
-
|
60
|
+
def from_upcase_first
|
61
|
+
I18n.t("#{composite_key}.from.upcase_first")
|
62
|
+
end
|
41
63
|
|
42
|
-
|
64
|
+
def to_sentence
|
65
|
+
I18n.t("#{composite_key}.to.sentence")
|
66
|
+
end
|
43
67
|
|
44
|
-
|
68
|
+
def to_upcase_first
|
69
|
+
I18n.t("#{composite_key}.to.upcase_first")
|
45
70
|
end
|
46
71
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
72
|
+
def from_formatted
|
73
|
+
@from_formatted ||= begin
|
74
|
+
from = I18n.l(from_date, format: from_sentence)
|
75
|
+
from = from.upcase_first if from_upcase_first
|
76
|
+
from
|
77
|
+
end
|
52
78
|
end
|
53
79
|
|
54
|
-
def
|
55
|
-
|
80
|
+
def to_formatted
|
81
|
+
return '' if no_end?
|
82
|
+
@to_formatted ||= begin
|
83
|
+
to = I18n.l(to_date, format: to_sentence)
|
84
|
+
to = to.upcase_first if to_upcase_first
|
85
|
+
to
|
86
|
+
end
|
56
87
|
end
|
57
88
|
|
58
|
-
def
|
59
|
-
|
89
|
+
def composite_key
|
90
|
+
"date_range.#{kind}.#{layout}.#{format}"
|
60
91
|
end
|
61
|
-
|
92
|
+
|
93
|
+
end
|
@@ -6,8 +6,9 @@
|
|
6
6
|
# Layout can be :one_line (default) or :two_lines, other might be necessary in the future
|
7
7
|
module I18nDateRangeHelper
|
8
8
|
|
9
|
-
def date_range_i18n(
|
10
|
-
I18nDateRangeGenerator.new(
|
9
|
+
def date_range_i18n(from_date, to_date = nil, **options)
|
10
|
+
generator = I18nDateRangeGenerator.new(from_date, to_date, **options.slice(:format, :layout))
|
11
|
+
generator.to_s.html_safe
|
11
12
|
end
|
12
13
|
|
13
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_date_range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pabois
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|
190
|
-
rubygems_version: 3.4
|
190
|
+
rubygems_version: 3.1.4
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: Add helper to display a date range
|