dotiw 5.1.0 → 5.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +8 -8
- data/CHANGELOG.md +21 -0
- data/README.markdown +26 -1
- data/benchmarks/time_hash_bench.rb +19 -0
- data/lib/dotiw/action_view/helpers/date_helper.rb +27 -7
- data/lib/dotiw/locale/ar.yml +54 -3
- data/lib/dotiw/locale/da.yml +35 -0
- data/lib/dotiw/locale/de.yml +36 -1
- data/lib/dotiw/locale/en.yml +35 -0
- data/lib/dotiw/locale/es.yml +36 -1
- data/lib/dotiw/locale/fr.yml +35 -0
- data/lib/dotiw/locale/id.yml +35 -0
- data/lib/dotiw/locale/it.yml +35 -0
- data/lib/dotiw/locale/ja.yml +35 -0
- data/lib/dotiw/locale/ko.yml +23 -0
- data/lib/dotiw/locale/nb.yml +36 -1
- data/lib/dotiw/locale/nl.yml +35 -0
- data/lib/dotiw/locale/pl.yml +35 -0
- data/lib/dotiw/locale/pt-BR.yml +35 -0
- data/lib/dotiw/locale/ru.yml +37 -0
- data/lib/dotiw/locale/sv.yml +48 -0
- data/lib/dotiw/locale/vi.yml +23 -0
- data/lib/dotiw/locale/zh-CN.yml +23 -0
- data/lib/dotiw/locale/zh-TW.yml +60 -0
- data/lib/dotiw/methods.rb +22 -7
- data/lib/dotiw/time_hash.rb +20 -14
- data/lib/dotiw/version.rb +1 -1
- data/lib/dotiw.rb +2 -1
- data/spec/lib/dotiw_spec.rb +171 -36
- data/spec/lib/i18n/sv.yml +2 -0
- data/spec/lib/i18n/zh-TW.yml +2 -0
- metadata +10 -3
data/spec/lib/dotiw_spec.rb
CHANGED
@@ -23,18 +23,19 @@ describe 'A better distance_of_time_in_words' do
|
|
23
23
|
|
24
24
|
describe '#distance_of_time' do
|
25
25
|
[
|
26
|
-
[0.5.minutes, '30 seconds'],
|
27
|
-
[4.5.minutes, '4 minutes and 30 seconds'],
|
28
|
-
[5.minutes, '5 minutes'],
|
29
|
-
[10.minutes, '10 minutes'],
|
30
|
-
[1.hour, '1 hour'],
|
31
|
-
[1.hour + 30.seconds, '1 hour and 30 seconds'],
|
32
|
-
[4.weeks, '4 weeks'],
|
33
|
-
[4.weeks + 2.days, '4 weeks and 2 days'],
|
34
|
-
[24.weeks, '5 months, 2 weeks, and 1 day']
|
35
|
-
].each do |number, result|
|
26
|
+
[0.5.minutes, '30 seconds', '30s'],
|
27
|
+
[4.5.minutes, '4 minutes and 30 seconds', '4m30s'],
|
28
|
+
[5.minutes.to_i, '5 minutes', '5m'],
|
29
|
+
[10.minutes.to_i, '10 minutes', '10m'],
|
30
|
+
[1.hour.to_i, '1 hour', '1h'],
|
31
|
+
[1.hour + 30.seconds, '1 hour and 30 seconds', '1h30s'],
|
32
|
+
[4.weeks.to_i, '4 weeks', '4w'],
|
33
|
+
[4.weeks + 2.days, '4 weeks and 2 days', '4w2d'],
|
34
|
+
[24.weeks.to_i, '5 months, 2 weeks, and 1 day', '5mo2w1d']
|
35
|
+
].each do |number, result, compact_result|
|
36
36
|
it "#{number} == #{result}" do
|
37
37
|
expect(distance_of_time(number)).to eq(result)
|
38
|
+
expect(distance_of_time(number, compact: true)).to eq(compact_result)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -100,6 +101,11 @@ describe 'A better distance_of_time_in_words' do
|
|
100
101
|
expect(DOTIW.languages.map(&:to_s).sort).to eq languages.sort
|
101
102
|
end
|
102
103
|
|
104
|
+
it 'raises ArgumentError when nil is passed for time' do
|
105
|
+
expect { distance_of_time_in_words(nil) }.to raise_error(ArgumentError)
|
106
|
+
expect { distance_of_time_in_words(nil, nil) }.to raise_error(ArgumentError)
|
107
|
+
end
|
108
|
+
|
103
109
|
DOTIW.languages.each do |lang|
|
104
110
|
context lang do
|
105
111
|
YAML.safe_load(
|
@@ -129,31 +135,33 @@ describe 'A better distance_of_time_in_words' do
|
|
129
135
|
end
|
130
136
|
|
131
137
|
[
|
132
|
-
[START_TIME, START_TIME + 5.days + 3.minutes, '5 days and 3 minutes'],
|
133
|
-
[START_TIME, START_TIME + 1.minute, '1 minute'],
|
134
|
-
[START_TIME, START_TIME + 3.years, '3 years'],
|
135
|
-
[START_TIME, START_TIME + 10.years, '10 years'],
|
136
|
-
[START_TIME, START_TIME + 8.months, '8 months'],
|
137
|
-
[START_TIME, START_TIME + 3.hour, '3 hours'],
|
138
|
-
[START_TIME, START_TIME + 13.months, '1 year and 1 month'],
|
138
|
+
[START_TIME, START_TIME + 5.days + 3.minutes, '5 days and 3 minutes', '5d3m'],
|
139
|
+
[START_TIME, START_TIME + 1.minute, '1 minute', '1m'],
|
140
|
+
[START_TIME, START_TIME + 3.years, '3 years', '3y'],
|
141
|
+
[START_TIME, START_TIME + 10.years, '10 years', '10y'],
|
142
|
+
[START_TIME, START_TIME + 8.months, '8 months', '8mo'],
|
143
|
+
[START_TIME, START_TIME + 3.hour, '3 hours', '3h'],
|
144
|
+
[START_TIME, START_TIME + 13.months, '1 year and 1 month', '1y1mo'],
|
139
145
|
# Any numeric sequence is merely coincidental.
|
140
|
-
[START_TIME, START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
141
|
-
|
142
|
-
['2009-3-16'.to_time
|
143
|
-
['2009-
|
144
|
-
['2009-
|
145
|
-
['
|
146
|
-
[
|
147
|
-
[Date.
|
148
|
-
[
|
149
|
-
['
|
150
|
-
['2014-1-31'.to_time, '2014-3-
|
151
|
-
['
|
152
|
-
['2016-1-31'.to_time, '2016-3-
|
153
|
-
|
146
|
+
[START_TIME, START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
147
|
+
'1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds', '1y2mo3w4d5h6m7s'],
|
148
|
+
['2009-3-16'.to_time, '2008-4-14'.to_time, '11 months and 2 days', '11mo2d'],
|
149
|
+
['2009-3-16'.to_time + 1.minute, '2008-4-14'.to_time, '11 months, 2 days, and 1 minute', '11mo2d1m'],
|
150
|
+
['2009-4-14'.to_time, '2008-3-16'.to_time, '1 year, 4 weeks, and 1 day', '1y4w1d'],
|
151
|
+
['2009-2-01'.to_time, '2009-3-01'.to_time, '1 month', '1mo'],
|
152
|
+
['2008-2-01'.to_time, '2008-3-01'.to_time, '1 month', '1mo'],
|
153
|
+
[Date.parse('31.03.2015').to_time, Time.parse('01.03.2016'), '10 months, 4 weeks, and 2 days', '10mo4w2d'],
|
154
|
+
[Date.new(2014, 1, 31), Date.new(2014, 3, 1), '4 weeks and 1 day', '4w1d'],
|
155
|
+
['2008-2-01'.to_time, '2008-3-01'.to_time, '1 month', '1mo'],
|
156
|
+
['2014-1-31'.to_time, '2014-3-01'.to_time, '4 weeks and 1 day', '4w1d'],
|
157
|
+
['2014-1-31'.to_time, '2014-3-02'.to_time, '4 weeks and 2 days', '4w2d'],
|
158
|
+
['2016-1-31'.to_time, '2016-3-01'.to_time, '4 weeks and 2 days', '4w2d'],
|
159
|
+
['2016-1-31'.to_time, '2016-3-02'.to_time, '1 month', '1mo']
|
160
|
+
].each do |start, finish, output, compact_result|
|
154
161
|
it "should be #{output}" do
|
155
162
|
expect(distance_of_time_in_words(start, finish, true)).to eq(output)
|
156
163
|
expect(distance_of_time_in_words(finish, start, true)).to eq(output)
|
164
|
+
expect(distance_of_time_in_words(start, finish, true, compact: true)).to eq(compact_result)
|
157
165
|
end
|
158
166
|
end
|
159
167
|
|
@@ -214,7 +222,7 @@ describe 'A better distance_of_time_in_words' do
|
|
214
222
|
expect(distance_of_time_in_words(start, finish, true, accumulate_on: accumulator)).to eq(output)
|
215
223
|
end
|
216
224
|
end
|
217
|
-
end
|
225
|
+
end
|
218
226
|
|
219
227
|
describe 'without finish time' do
|
220
228
|
# A missing finish argument should default to zero, essentially returning
|
@@ -312,7 +320,34 @@ describe 'A better distance_of_time_in_words' do
|
|
312
320
|
end
|
313
321
|
|
314
322
|
if defined?(ActionView)
|
315
|
-
describe 'ActionView' do
|
323
|
+
describe 'ActionView without include seconds argument' do
|
324
|
+
[
|
325
|
+
[START_TIME,
|
326
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
327
|
+
{ vague: true },
|
328
|
+
'about 1 year'],
|
329
|
+
[START_TIME,
|
330
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
331
|
+
{ vague: 'Yes please' },
|
332
|
+
'about 1 year'],
|
333
|
+
[START_TIME,
|
334
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
335
|
+
{ vague: false },
|
336
|
+
'1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes'],
|
337
|
+
[START_TIME,
|
338
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
339
|
+
{ vague: nil },
|
340
|
+
'1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes']
|
341
|
+
].each do |start, finish, options, output|
|
342
|
+
it "should be #{output}" do
|
343
|
+
expect(distance_of_time_in_words(start, finish, options)).to eq(output)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
if defined?(ActionView)
|
350
|
+
describe 'ActionView with include seconds argument' do
|
316
351
|
[
|
317
352
|
[START_TIME,
|
318
353
|
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
@@ -335,12 +370,13 @@ describe 'A better distance_of_time_in_words' do
|
|
335
370
|
expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
|
336
371
|
end
|
337
372
|
end
|
338
|
-
|
373
|
+
|
339
374
|
context 'via ActionController::Base.helpers' do
|
340
375
|
it '#distance_of_time_in_words' do
|
341
376
|
end_time = START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds
|
342
377
|
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,
|
378
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words(START_TIME, end_time, true,
|
379
|
+
{ vague: false })
|
344
380
|
expect(actual).to eq(expected)
|
345
381
|
end
|
346
382
|
|
@@ -349,6 +385,105 @@ describe 'A better distance_of_time_in_words' do
|
|
349
385
|
actual = ActionController::Base.helpers.time_ago_in_words(Time.now - 3.days - 14.minutes)
|
350
386
|
expect(actual).to eq(expected)
|
351
387
|
end
|
388
|
+
|
389
|
+
describe '#distance_of_time_in_words_to_now' do
|
390
|
+
context 'with nil' do
|
391
|
+
it 'raises ArgumentError when nil is passed for time' do
|
392
|
+
expect do
|
393
|
+
ActionController::Base.helpers.distance_of_time_in_words_to_now(nil)
|
394
|
+
end.to raise_error(ArgumentError)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context 'without options' do
|
399
|
+
it 'shows detailed duration without seconds' do
|
400
|
+
expected = '3 days and 14 minutes'
|
401
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(Time.now - 3.days - 14.minutes)
|
402
|
+
expect(actual).to eq(expected)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'with seconds false and vague option true' do
|
407
|
+
it 'shows vague duration' do
|
408
|
+
expected = '3 days'
|
409
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
410
|
+
Time.now - 3.days - 14.minutes - 20.seconds, false, vague: true
|
411
|
+
)
|
412
|
+
expect(actual).to eq(expected)
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
context 'with seconds true and vague option true' do
|
417
|
+
it 'shows vague duration' do
|
418
|
+
expected = '3 days'
|
419
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
420
|
+
Time.now - 3.days - 14.minutes - 20.seconds, true, vague: true
|
421
|
+
)
|
422
|
+
expect(actual).to eq(expected)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
context 'with seconds false and vague option false' do
|
427
|
+
it 'shows detailed duration without seconds' do
|
428
|
+
expected = '3 days and 14 minutes'
|
429
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
430
|
+
Time.now - 3.days - 14.minutes - 20.seconds, false, vague: false
|
431
|
+
)
|
432
|
+
expect(actual).to eq(expected)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context 'with seconds true and vague option false' do
|
437
|
+
it 'shows detailed duration with seconds' do
|
438
|
+
expected = '3 days, 14 minutes, and 20 seconds'
|
439
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
440
|
+
Time.now - 3.days - 14.minutes - 20.seconds, true, vague: false
|
441
|
+
)
|
442
|
+
expect(actual).to eq(expected)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
context 'without seconds and vague option false' do
|
447
|
+
it 'shows detailed duration without seconds' do
|
448
|
+
expected = '3 days and 14 minutes'
|
449
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
450
|
+
Time.now - 3.days - 14.minutes - 20.seconds, vague: false
|
451
|
+
)
|
452
|
+
expect(actual).to eq(expected)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
context 'without seconds and vague option true' do
|
457
|
+
it 'shows vague duration' do
|
458
|
+
expected = '3 days'
|
459
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
460
|
+
Time.now - 3.days - 14.minutes - 20.seconds, vague: true
|
461
|
+
)
|
462
|
+
expect(actual).to eq(expected)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
context 'with options include_seconds true and vague option false' do
|
467
|
+
it 'shows detailed duration with seconds' do
|
468
|
+
expected = '3 days, 14 minutes, and 20 seconds'
|
469
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
470
|
+
Time.now - 3.days - 14.minutes - 20.seconds, {include_seconds: true, vague: false}
|
471
|
+
)
|
472
|
+
expect(actual).to eq(expected)
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
context 'with options include_seconds false and vague option true' do
|
477
|
+
it 'shows vague duration' do
|
478
|
+
expected = '3 days'
|
479
|
+
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
480
|
+
Time.now - 3.days - 14.minutes - 20.seconds, {include_seconds: false, vague: true}
|
481
|
+
)
|
482
|
+
expect(actual).to eq(expected)
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
end
|
352
487
|
end
|
353
488
|
end
|
354
489
|
end
|
@@ -367,7 +502,7 @@ describe 'A better distance_of_time_in_words' do
|
|
367
502
|
)
|
368
503
|
).to eq('1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes')
|
369
504
|
end
|
370
|
-
end
|
505
|
+
end
|
371
506
|
end
|
372
507
|
|
373
508
|
if defined?(ActionView)
|
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.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- MIT-LICENSE
|
147
147
|
- README.markdown
|
148
148
|
- Rakefile
|
149
|
+
- benchmarks/time_hash_bench.rb
|
149
150
|
- dotiw.gemspec
|
150
151
|
- gemfiles/.bundle/config
|
151
152
|
- gemfiles/rails_4.gemfile
|
@@ -170,8 +171,10 @@ files:
|
|
170
171
|
- lib/dotiw/locale/pl.yml
|
171
172
|
- lib/dotiw/locale/pt-BR.yml
|
172
173
|
- lib/dotiw/locale/ru.yml
|
174
|
+
- lib/dotiw/locale/sv.yml
|
173
175
|
- lib/dotiw/locale/vi.yml
|
174
176
|
- lib/dotiw/locale/zh-CN.yml
|
177
|
+
- lib/dotiw/locale/zh-TW.yml
|
175
178
|
- lib/dotiw/methods.rb
|
176
179
|
- lib/dotiw/time_hash.rb
|
177
180
|
- lib/dotiw/version.rb
|
@@ -191,8 +194,10 @@ files:
|
|
191
194
|
- spec/lib/i18n/pl.yml
|
192
195
|
- spec/lib/i18n/pt-BR.yml
|
193
196
|
- spec/lib/i18n/ru.yml
|
197
|
+
- spec/lib/i18n/sv.yml
|
194
198
|
- spec/lib/i18n/vi.yml
|
195
199
|
- spec/lib/i18n/zh-CN.yml
|
200
|
+
- spec/lib/i18n/zh-TW.yml
|
196
201
|
- spec/spec_helper.rb
|
197
202
|
homepage: https://github.com/radar/distance_of_time_in_words
|
198
203
|
licenses:
|
@@ -213,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
218
|
- !ruby/object:Gem::Version
|
214
219
|
version: '0'
|
215
220
|
requirements: []
|
216
|
-
rubygems_version: 3.1.
|
221
|
+
rubygems_version: 3.1.3
|
217
222
|
signing_key:
|
218
223
|
specification_version: 4
|
219
224
|
summary: Better distance_of_time_in_words for Rails
|
@@ -234,6 +239,8 @@ test_files:
|
|
234
239
|
- spec/lib/i18n/pl.yml
|
235
240
|
- spec/lib/i18n/pt-BR.yml
|
236
241
|
- spec/lib/i18n/ru.yml
|
242
|
+
- spec/lib/i18n/sv.yml
|
237
243
|
- spec/lib/i18n/vi.yml
|
238
244
|
- spec/lib/i18n/zh-CN.yml
|
245
|
+
- spec/lib/i18n/zh-TW.yml
|
239
246
|
- spec/spec_helper.rb
|