dotiw 5.3.1 → 5.3.2
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 +4 -0
- data/README.markdown +6 -0
- data/lib/dotiw/action_view/helpers/date_helper.rb +16 -4
- data/lib/dotiw/version.rb +1 -1
- data/spec/lib/dotiw_spec.rb +96 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bbd17f6b2f3af46a5255fa9eb900aa7bb734ead661088a2936739aa2f2bef63
|
4
|
+
data.tar.gz: 2870eadd1e540d51e6ff73210024fbcb87de8c01cca2549d7fb80e30b4390d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a89bfcad7275d64474969ac9200f43d6b5b3fb922c6cfa9e4bc05550361f43dc3d1eb37c27771116dc51cfba6adfa844232fbc062592dfa2874ff0e355797c3b
|
7
|
+
data.tar.gz: 8379db832851f15302fa364103671c3d805c0f367d8c8c0be4d746e81a473ab4b7d49c29a248fd353410a14e22ed04db79a1bfb05b83f4fd52403781460712fa
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 5.3.2 (2021/11/08)
|
2
|
+
|
3
|
+
* [#126](https://github.com/radar/distance_of_time_in_words/pull/126): Fixes `#distance_of_time_in_words_to_now` with `vague: true` when supplied without `include_seconds` argument - [@mozcomp](https://github.com/mozcomp).
|
4
|
+
|
1
5
|
## 5.3.1 (2021/03/26)
|
2
6
|
|
3
7
|
* [#124](https://github.com/radar/distance_of_time_in_words/pull/124): Fixes compact formatting for distance_of_time_in_words - [@rposborne](https://github.com/rposborne).
|
data/README.markdown
CHANGED
@@ -67,6 +67,8 @@ The third argument for this method is whether or not to include seconds. By defa
|
|
67
67
|
|
68
68
|
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility", because that's just an insanely radical thing to do. \m/
|
69
69
|
|
70
|
+
Alternatively this can be included in the options hash as `include_seconds: true` removing this argument altogether.
|
71
|
+
|
70
72
|
The last argument is an optional options hash that can be used to manipulate behavior and (which uses `to_sentence`).
|
71
73
|
|
72
74
|
Don't like having to pass in `Time.now` all the time? Then use `time_ago_in_words` or `distance_of_time_in_words_to_now` which also will *rock your
|
@@ -99,6 +101,10 @@ This will also be passed to `to_sentence`.
|
|
99
101
|
|
100
102
|
Specify this if you want it to use the old `distance_of_time_in_words`. The value can be anything except `nil` or `false`.
|
101
103
|
|
104
|
+
#### :include_seconds
|
105
|
+
|
106
|
+
As described above this option is the equivalent to the third argument whether to include seconds.
|
107
|
+
|
102
108
|
#### :accumulate_on
|
103
109
|
|
104
110
|
Specifies the maximum output unit which will accumulate all the surplus. Say you set it to seconds and your time difference is of 2 minutes then the output would be 120 seconds.
|
@@ -9,15 +9,17 @@ module ActionView
|
|
9
9
|
include DOTIW::Methods
|
10
10
|
|
11
11
|
def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
|
12
|
-
|
12
|
+
options = merge_options(include_seconds_or_options, options)
|
13
|
+
return _distance_of_time_in_words(from_time, to_time, options.except(:vague)) if options[:vague]
|
13
14
|
|
14
|
-
DOTIW::Methods.distance_of_time_in_words(from_time, to_time,
|
15
|
+
DOTIW::Methods.distance_of_time_in_words(from_time, to_time, options.except(:vague))
|
15
16
|
end
|
16
17
|
|
17
18
|
def distance_of_time_in_words_to_now(to_time = 0, include_seconds_or_options = {}, options = {})
|
18
|
-
|
19
|
+
options = merge_options(include_seconds_or_options, options)
|
20
|
+
return _distance_of_time_in_words(Time.now, to_time, options.except(:vague)) if options[:vague]
|
19
21
|
|
20
|
-
DOTIW::Methods.distance_of_time_in_words(Time.now, to_time,
|
22
|
+
DOTIW::Methods.distance_of_time_in_words(Time.now, to_time, options.except(:vague))
|
21
23
|
end
|
22
24
|
|
23
25
|
def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
|
@@ -27,6 +29,16 @@ module ActionView
|
|
27
29
|
result = ((current_time - from_time) / distance) * 100
|
28
30
|
number_with_precision(result, options).to_s + '%'
|
29
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def merge_options(include_seconds_or_options, options)
|
35
|
+
if include_seconds_or_options.is_a?(Hash)
|
36
|
+
options.merge(include_seconds_or_options)
|
37
|
+
else
|
38
|
+
options.merge(include_seconds: !!include_seconds_or_options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
data/lib/dotiw/version.rb
CHANGED
data/spec/lib/dotiw_spec.rb
CHANGED
@@ -320,7 +320,34 @@ describe 'A better distance_of_time_in_words' do
|
|
320
320
|
end
|
321
321
|
|
322
322
|
if defined?(ActionView)
|
323
|
-
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
|
324
351
|
[
|
325
352
|
[START_TIME,
|
326
353
|
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
@@ -343,7 +370,7 @@ describe 'A better distance_of_time_in_words' do
|
|
343
370
|
expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
|
344
371
|
end
|
345
372
|
end
|
346
|
-
|
373
|
+
|
347
374
|
context 'via ActionController::Base.helpers' do
|
348
375
|
it '#distance_of_time_in_words' do
|
349
376
|
end_time = START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds
|
@@ -369,32 +396,93 @@ describe 'A better distance_of_time_in_words' do
|
|
369
396
|
end
|
370
397
|
|
371
398
|
context 'without options' do
|
372
|
-
it 'shows detailed duration' do
|
399
|
+
it 'shows detailed duration without seconds' do
|
373
400
|
expected = '3 days and 14 minutes'
|
374
401
|
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(Time.now - 3.days - 14.minutes)
|
375
402
|
expect(actual).to eq(expected)
|
376
403
|
end
|
377
404
|
end
|
378
405
|
|
379
|
-
context 'with vague option true' do
|
406
|
+
context 'with seconds false and vague option true' do
|
380
407
|
it 'shows vague duration' do
|
381
408
|
expected = '3 days'
|
382
409
|
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
383
|
-
Time.now - 3.days - 14.minutes, false, vague: true
|
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
|
384
431
|
)
|
385
432
|
expect(actual).to eq(expected)
|
386
433
|
end
|
387
434
|
end
|
388
435
|
|
389
|
-
context 'with vague option false' do
|
390
|
-
it 'shows detailed duration' do
|
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
|
391
448
|
expected = '3 days and 14 minutes'
|
392
449
|
actual = ActionController::Base.helpers.distance_of_time_in_words_to_now(
|
393
|
-
Time.now - 3.days - 14.minutes
|
450
|
+
Time.now - 3.days - 14.minutes - 20.seconds, vague: false
|
394
451
|
)
|
395
452
|
expect(actual).to eq(expected)
|
396
453
|
end
|
397
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
|
+
|
398
486
|
end
|
399
487
|
end
|
400
488
|
end
|
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.3.
|
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: 2021-
|
12
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|