diff options
| author | Baptiste Fontaine | 2015-12-14 14:57:17 +0100 |
|---|---|---|
| committer | Baptiste Fontaine | 2015-12-14 16:34:12 +0100 |
| commit | f1ac9b5776bbd49c9ce71b4ddf138bcc61b9b8f6 (patch) | |
| tree | c34058ca30ede73e397e9230103838963878860e /Library | |
| parent | 9127ee1928c1de98f1f158dd4169e2e3a5a90275 (diff) | |
| download | brew-f1ac9b5776bbd49c9ce71b4ddf138bcc61b9b8f6.tar.bz2 | |
pretty_duration: fixed for int arguments
Without this the returned string is not as accurate if the method is
called with an int larger than 120.
Closes Homebrew/homebrew#47002.
Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/test/test_utils.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index 0be6f50eb..f533e3f90 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -48,6 +48,14 @@ class UtilTests < Homebrew::TestCase assert_predicate $?, :success? end + def test_pretty_duration + assert_equal "2 seconds", pretty_duration(1) + assert_equal "2 seconds", pretty_duration(2.5) + assert_equal "42 seconds", pretty_duration(42) + assert_equal "4.2 minutes", pretty_duration(252) + assert_equal "4.2 minutes", pretty_duration(252.45) + end + def test_plural assert_equal "", plural(1) assert_equal "s", plural(0) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index c874ec03c..b1a242044 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -140,7 +140,7 @@ end def pretty_duration(s) return "2 seconds" if s < 3 # avoids the plural problem ;) return "#{s.to_i} seconds" if s < 120 - "%.1f minutes" % (s/60) + "%.1f minutes" % (s/60.0) end def plural(n, s = "s") |
