duration-formatter 1.2.0 → 1.2.1
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/lib/duration_formatter/version.rb +1 -1
- data/lib/formatted_duration.rb +3 -3
- data/test/lib/formatted_duration_test.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df4d194657d59865ae0d44290263010138427489
|
4
|
+
data.tar.gz: f34c0b4ad810fcf299d7e7bb763b004b5c14576c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8d825ca8858478a595d726f5549124ea73ba26fb011b3e3e36a3efc597e932fdc10701e0b3f2bd2f53d60d0843d4818bd9e5189d52fac2b5e3b474546917d32
|
7
|
+
data.tar.gz: a0b8929d9e5d3403c7ff4bfc53f7ca2d290e19fad216d0ada0ef22f4598cbace0b5d919423e8233a4a9eeff6b470d99c53f170b541e885ae29696ce3800121c2
|
data/lib/formatted_duration.rb
CHANGED
@@ -16,7 +16,7 @@ class FormattedDuration
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def format
|
19
|
-
append(:weeks, @weeks, '%w %~w') if @weeks
|
19
|
+
append(:weeks, @weeks, '%w %~w') if @weeks > 0 && @constraint > 2
|
20
20
|
add(:days, @days, 2)
|
21
21
|
add(:hours, @hours, 1)
|
22
22
|
add(:minutes, @minutes, 0)
|
@@ -34,9 +34,9 @@ class FormattedDuration
|
|
34
34
|
def add(unit, value, constraint)
|
35
35
|
bare = value % BARE[unit]
|
36
36
|
|
37
|
-
if value
|
37
|
+
if value > 0 && @constraint == constraint
|
38
38
|
append(unit, value, FORMATS[unit])
|
39
|
-
elsif bare
|
39
|
+
elsif bare > 0 && @constraint > constraint - 1
|
40
40
|
append(unit, bare, BARE_FORMATS[unit])
|
41
41
|
end
|
42
42
|
end
|
@@ -6,7 +6,7 @@ class FormattedDurationTest < Minitest::Test
|
|
6
6
|
|
7
7
|
def test_weeks_only_duration
|
8
8
|
text = '1 week'
|
9
|
-
output = FormattedDuration.new(
|
9
|
+
output = FormattedDuration.new(10080).format
|
10
10
|
|
11
11
|
assert_equal text, output
|
12
12
|
end
|
@@ -36,7 +36,7 @@ class FormattedDurationTest < Minitest::Test
|
|
36
36
|
|
37
37
|
def test_weeks_and_days_duration
|
38
38
|
text = '1 week, 4 days'
|
39
|
-
output = FormattedDuration.new(
|
39
|
+
output = FormattedDuration.new(15840).format
|
40
40
|
|
41
41
|
assert_equal text, output
|
42
42
|
end
|
@@ -59,7 +59,7 @@ class FormattedDurationTest < Minitest::Test
|
|
59
59
|
|
60
60
|
def test_days_constraint
|
61
61
|
text = '8 days'
|
62
|
-
output = FormattedDuration.new(
|
62
|
+
output = FormattedDuration.new(11520, :days).format
|
63
63
|
|
64
64
|
assert_equal text, output
|
65
65
|
end
|