dotiw 5.0.0 → 5.1.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/CHANGELOG.md +5 -0
- data/dotiw.gemspec +2 -2
- data/lib/dotiw.rb +10 -3
- data/lib/dotiw/action_view/helpers/date_helper.rb +1 -1
- data/lib/dotiw/locale/vi.yml +25 -0
- data/lib/dotiw/methods.rb +2 -0
- data/lib/dotiw/version.rb +1 -1
- data/spec/lib/dotiw_spec.rb +69 -13
- data/spec/lib/i18n/ar.yml +2 -0
- data/spec/lib/i18n/da.yml +2 -0
- data/spec/lib/i18n/de.yml +2 -0
- data/spec/lib/i18n/en.yml +2 -0
- data/spec/lib/i18n/es.yml +3 -0
- data/spec/lib/i18n/fr.yml +2 -0
- data/spec/lib/i18n/id.yml +2 -0
- data/spec/lib/i18n/it.yml +3 -0
- data/spec/lib/i18n/ja.yml +2 -0
- data/spec/lib/i18n/ko.yml +2 -0
- data/spec/lib/i18n/nb.yml +2 -0
- data/spec/lib/i18n/nl.yml +2 -0
- data/spec/lib/i18n/pl.yml +2 -0
- data/spec/lib/i18n/pt-BR.yml +2 -0
- data/spec/lib/i18n/ru.yml +5 -0
- data/spec/lib/i18n/vi.yml +22 -0
- data/spec/lib/i18n/zh-CN.yml +2 -0
- metadata +40 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c3178c4c07b2647581895e344418e9ce40e3da5d9e3cc1fda714f9817b852e8
|
4
|
+
data.tar.gz: cef2e7944c792c501181789e3ed9f0155e12be6954e40664f495bcb298f40709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db64efc0d3189bca7be013a3faff83820392bcfc69bf111497ea3543d67eba53f3792f62e6c43b1d39b73a6d6fb32811b6ae4f511f04c19d069283cdd18f355
|
7
|
+
data.tar.gz: a9bae3a175fada3623c8275abec2052e377716db914dadd0b2908a33fbff67fa95191062cb37cb20d15a90478b61ddc9647140d04dc37f0be73fd44b833e7957
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 5.1.0 (2020/08/05)
|
2
|
+
|
3
|
+
* [#111](https://github.com/radar/distance_of_time_in_words/pull/111): Fix: `NoMethodError` when calling `ActionController::Base.helpers.distance_of_time_in_words` - [@denisahearn](https://github.com/denisahearn).
|
4
|
+
* [#106](https://github.com/radar/distance_of_time_in_words/pull/106): Add Vietnamese language support - [@runlevel5 ](https://github.com/runlevel5).
|
5
|
+
|
1
6
|
## 5.0.0 (2020/05/07)
|
2
7
|
|
3
8
|
* [#105](https://github.com/radar/distance_of_time_in_words/pull/105): Support for Ruby w/o Rails - [@dblock](https://github.com/dblock).
|
data/dotiw.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.version = DOTIW::VERSION
|
9
9
|
s.licenses = ['MIT']
|
10
10
|
|
11
|
-
s.authors = [
|
11
|
+
s.authors = ['Ryan Bigg', 'Lauran Jansen']
|
12
12
|
s.description = "dotiw is a gem for Rails that overrides the
|
13
13
|
default distance_of_time_in_words and provides
|
14
14
|
a more accurate output. Do you crave accuracy
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.email = ['radarlistener@gmail.com', 'github@lauranjansen.com']
|
19
19
|
s.homepage = 'https://github.com/radar/distance_of_time_in_words'
|
20
20
|
|
21
|
-
s.add_dependency 'i18n'
|
22
21
|
s.add_dependency 'activesupport'
|
22
|
+
s.add_dependency 'i18n'
|
23
23
|
|
24
24
|
s.add_development_dependency 'appraisal'
|
25
25
|
s.add_development_dependency 'bundler'
|
data/lib/dotiw.rb
CHANGED
@@ -23,11 +23,18 @@ module DOTIW
|
|
23
23
|
I18n.reload!
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
def languages
|
27
|
+
@languages ||= (locale_files.map { |path| path.split(%r{[/.]})[-2].to_sym })
|
28
|
+
end
|
27
29
|
|
28
|
-
# Returns all locale files shipped with library
|
29
30
|
def locale_files
|
30
|
-
|
31
|
+
files 'dotiw/locale', '*.yml'
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def files(directory, ext)
|
37
|
+
Dir[File.join File.dirname(__FILE__), directory, ext]
|
31
38
|
end
|
32
39
|
end # DOTIW
|
33
40
|
|
@@ -10,7 +10,7 @@ module ActionView
|
|
10
10
|
|
11
11
|
def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
|
12
12
|
return _distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague)
|
13
|
-
|
13
|
+
DOTIW::Methods.distance_of_time_in_words(from_time, to_time, include_seconds_or_options, options)
|
14
14
|
end
|
15
15
|
|
16
16
|
def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
|
@@ -0,0 +1,25 @@
|
|
1
|
+
vi:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 1 giây
|
6
|
+
other: "%{count} giây"
|
7
|
+
minutes:
|
8
|
+
one: 1 phút
|
9
|
+
other: "%{count} phút"
|
10
|
+
hours:
|
11
|
+
one: 1 giờ
|
12
|
+
other: "%{count} giờ"
|
13
|
+
days:
|
14
|
+
one: 1 ngày
|
15
|
+
other: "%{count} ngày"
|
16
|
+
weeks:
|
17
|
+
one: 1 tuần
|
18
|
+
other: "%{count} tuần"
|
19
|
+
months:
|
20
|
+
one: 1 tháng
|
21
|
+
other: "%{count} tháng"
|
22
|
+
years:
|
23
|
+
one: 1 năm
|
24
|
+
other: "%{count} năm"
|
25
|
+
less_than_x: "ít hơn %{distance}"
|
data/lib/dotiw/methods.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module DOTIW
|
4
4
|
module Methods
|
5
|
+
extend self
|
6
|
+
|
5
7
|
def distance_of_time_in_words_hash(from_time, to_time, options = {})
|
6
8
|
from_time = from_time.to_time if !from_time.is_a?(Time) && from_time.respond_to?(:to_time)
|
7
9
|
to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time)
|
data/lib/dotiw/version.rb
CHANGED
data/spec/lib/dotiw_spec.rb
CHANGED
@@ -7,6 +7,8 @@ describe 'A better distance_of_time_in_words' do
|
|
7
7
|
include ActionView::Helpers::DateHelper
|
8
8
|
include ActionView::Helpers::TextHelper
|
9
9
|
include ActionView::Helpers::NumberHelper
|
10
|
+
|
11
|
+
require 'action_controller'
|
10
12
|
else
|
11
13
|
include DOTIW::Methods
|
12
14
|
end
|
@@ -19,7 +21,7 @@ describe 'A better distance_of_time_in_words' do
|
|
19
21
|
allow(Time.zone).to receive(:now).and_return(START_TIME)
|
20
22
|
end
|
21
23
|
|
22
|
-
describe '
|
24
|
+
describe '#distance_of_time' do
|
23
25
|
[
|
24
26
|
[0.5.minutes, '30 seconds'],
|
25
27
|
[4.5.minutes, '4 minutes and 30 seconds'],
|
@@ -48,7 +50,7 @@ describe 'A better distance_of_time_in_words' do
|
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
|
-
describe '
|
53
|
+
describe '#distance_of_time_in_words_hash' do
|
52
54
|
describe 'giving correct numbers of' do
|
53
55
|
%i[years months weeks days minutes seconds].each do |name|
|
54
56
|
describe name do
|
@@ -80,15 +82,50 @@ describe 'A better distance_of_time_in_words' do
|
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
|
-
describe '
|
84
|
-
it '
|
85
|
-
expect(
|
86
|
-
expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, locale: :es)).to eq('5 días')
|
85
|
+
describe '#time_ago_in_words' do
|
86
|
+
it 'aliases to distance_of_time_in_words' do
|
87
|
+
expect(time_ago_in_words(Time.now - 3.days - 14.minutes)).to eq('3 days and 14 minutes')
|
87
88
|
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#distance_of_time_in_words' do
|
92
|
+
context 'locale' do
|
93
|
+
it 'includes known languages' do
|
94
|
+
expect(DOTIW.languages).to include :en
|
95
|
+
expect(DOTIW.languages).to include :ru
|
96
|
+
end
|
88
97
|
|
89
|
-
|
90
|
-
|
91
|
-
|
98
|
+
it 'includes all the languages in specs' do
|
99
|
+
languages = Dir[File.join(File.dirname(__FILE__), 'i18n', '*.yml')].map { |f| File.basename(f, '.yml') }
|
100
|
+
expect(DOTIW.languages.map(&:to_s).sort).to eq languages.sort
|
101
|
+
end
|
102
|
+
|
103
|
+
DOTIW.languages.each do |lang|
|
104
|
+
context lang do
|
105
|
+
YAML.safe_load(
|
106
|
+
File.read(
|
107
|
+
File.join(
|
108
|
+
File.dirname(__FILE__), 'i18n', "#{lang}.yml"
|
109
|
+
)
|
110
|
+
)
|
111
|
+
).each_pair do |category, fixtures|
|
112
|
+
context category do
|
113
|
+
fixtures.each_pair do |k, v|
|
114
|
+
it v do
|
115
|
+
expect(
|
116
|
+
distance_of_time_in_words(
|
117
|
+
START_TIME,
|
118
|
+
START_TIME + eval(k),
|
119
|
+
true,
|
120
|
+
locale: lang
|
121
|
+
)
|
122
|
+
).to eq(v)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
92
129
|
end
|
93
130
|
|
94
131
|
[
|
@@ -145,7 +182,7 @@ describe 'A better distance_of_time_in_words' do
|
|
145
182
|
end
|
146
183
|
end
|
147
184
|
|
148
|
-
describe '
|
185
|
+
describe 'accumulate_on:' do
|
149
186
|
[
|
150
187
|
[START_TIME,
|
151
188
|
START_TIME + 10.minute,
|
@@ -298,6 +335,21 @@ describe 'A better distance_of_time_in_words' do
|
|
298
335
|
expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
|
299
336
|
end
|
300
337
|
end
|
338
|
+
|
339
|
+
context 'via ActionController::Base.helpers' do
|
340
|
+
it '#distance_of_time_in_words' do
|
341
|
+
end_time = START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds
|
342
|
+
expected = '1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds'
|
343
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words(START_TIME, end_time, true, { vague: false })
|
344
|
+
expect(actual).to eq(expected)
|
345
|
+
end
|
346
|
+
|
347
|
+
it '#time_ago_in_words' do
|
348
|
+
expected = '3 days and 14 minutes'
|
349
|
+
actual = ActionController::Base.helpers.time_ago_in_words(Time.now - 3.days - 14.minutes)
|
350
|
+
expect(actual).to eq(expected)
|
351
|
+
end
|
352
|
+
end
|
301
353
|
end
|
302
354
|
end
|
303
355
|
|
@@ -307,9 +359,13 @@ describe 'A better distance_of_time_in_words' do
|
|
307
359
|
end
|
308
360
|
|
309
361
|
it 'removes seconds in all other cases' do
|
310
|
-
expect(
|
311
|
-
|
312
|
-
|
362
|
+
expect(
|
363
|
+
distance_of_time_in_words(
|
364
|
+
START_TIME,
|
365
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
366
|
+
false
|
367
|
+
)
|
368
|
+
).to eq('1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes')
|
313
369
|
end
|
314
370
|
end # include_seconds
|
315
371
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
seconds:
|
2
|
+
0.5.second: ít hơn 1 giây
|
3
|
+
1.second: 1 giây
|
4
|
+
3.seconds: 3 giây
|
5
|
+
minutes:
|
6
|
+
1.minute: 1 phút
|
7
|
+
10.minutes: 10 phút
|
8
|
+
hours:
|
9
|
+
1.hour: 1 giờ
|
10
|
+
2.hours: 2 giờ
|
11
|
+
days:
|
12
|
+
1.day: 1 ngày
|
13
|
+
2.days: 2 ngày
|
14
|
+
weeks:
|
15
|
+
1.week: 1 tuần
|
16
|
+
2.weeks: 2 tuần
|
17
|
+
months:
|
18
|
+
1.month: 1 tháng
|
19
|
+
2.months: 2 tháng
|
20
|
+
years:
|
21
|
+
1.year: 1 năm
|
22
|
+
2.years: 2 năm
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotiw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: i18n
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
@@ -170,11 +170,29 @@ files:
|
|
170
170
|
- lib/dotiw/locale/pl.yml
|
171
171
|
- lib/dotiw/locale/pt-BR.yml
|
172
172
|
- lib/dotiw/locale/ru.yml
|
173
|
+
- lib/dotiw/locale/vi.yml
|
173
174
|
- lib/dotiw/locale/zh-CN.yml
|
174
175
|
- lib/dotiw/methods.rb
|
175
176
|
- lib/dotiw/time_hash.rb
|
176
177
|
- lib/dotiw/version.rb
|
177
178
|
- spec/lib/dotiw_spec.rb
|
179
|
+
- spec/lib/i18n/ar.yml
|
180
|
+
- spec/lib/i18n/da.yml
|
181
|
+
- spec/lib/i18n/de.yml
|
182
|
+
- spec/lib/i18n/en.yml
|
183
|
+
- spec/lib/i18n/es.yml
|
184
|
+
- spec/lib/i18n/fr.yml
|
185
|
+
- spec/lib/i18n/id.yml
|
186
|
+
- spec/lib/i18n/it.yml
|
187
|
+
- spec/lib/i18n/ja.yml
|
188
|
+
- spec/lib/i18n/ko.yml
|
189
|
+
- spec/lib/i18n/nb.yml
|
190
|
+
- spec/lib/i18n/nl.yml
|
191
|
+
- spec/lib/i18n/pl.yml
|
192
|
+
- spec/lib/i18n/pt-BR.yml
|
193
|
+
- spec/lib/i18n/ru.yml
|
194
|
+
- spec/lib/i18n/vi.yml
|
195
|
+
- spec/lib/i18n/zh-CN.yml
|
178
196
|
- spec/spec_helper.rb
|
179
197
|
homepage: https://github.com/radar/distance_of_time_in_words
|
180
198
|
licenses:
|
@@ -195,10 +213,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
213
|
- !ruby/object:Gem::Version
|
196
214
|
version: '0'
|
197
215
|
requirements: []
|
198
|
-
rubygems_version: 3.1.
|
216
|
+
rubygems_version: 3.1.2
|
199
217
|
signing_key:
|
200
218
|
specification_version: 4
|
201
219
|
summary: Better distance_of_time_in_words for Rails
|
202
220
|
test_files:
|
203
221
|
- spec/lib/dotiw_spec.rb
|
222
|
+
- spec/lib/i18n/ar.yml
|
223
|
+
- spec/lib/i18n/da.yml
|
224
|
+
- spec/lib/i18n/de.yml
|
225
|
+
- spec/lib/i18n/en.yml
|
226
|
+
- spec/lib/i18n/es.yml
|
227
|
+
- spec/lib/i18n/fr.yml
|
228
|
+
- spec/lib/i18n/id.yml
|
229
|
+
- spec/lib/i18n/it.yml
|
230
|
+
- spec/lib/i18n/ja.yml
|
231
|
+
- spec/lib/i18n/ko.yml
|
232
|
+
- spec/lib/i18n/nb.yml
|
233
|
+
- spec/lib/i18n/nl.yml
|
234
|
+
- spec/lib/i18n/pl.yml
|
235
|
+
- spec/lib/i18n/pt-BR.yml
|
236
|
+
- spec/lib/i18n/ru.yml
|
237
|
+
- spec/lib/i18n/vi.yml
|
238
|
+
- spec/lib/i18n/zh-CN.yml
|
204
239
|
- spec/spec_helper.rb
|