Permalink
Browse files

Add years counter to humanize helper

  • Loading branch information...
1 parent 39dc768 commit fc25f4366b7dd8066e26dae3a7232ee84cf6e7c3 @potomak potomak committed Nov 29, 2011
Showing with 5 additions and 2 deletions.
  1. +1 −1 app/helpers/application_helper.rb
  2. +4 −1 test/unit/helpers/application_helper_test.rb
@@ -11,7 +11,7 @@ def relative_day(date)
end
def humanize(secs)
- [[60, "second"], [60, "minute"], [24, "hour"], [1000, "day"]].map do |count, name|
+ [[60, "second"], [60, "minute"], [24, "hour"], [365, "day"], [1000, "year"]].map do |count, name|
if secs > 0
secs, n = secs.divmod(count)
pluralize(n.to_i, name) if n.to_i > 0
@@ -22,7 +22,10 @@ class ApplicationHelperTest < ActionView::TestCase
[
{:secs => 30, :string => '30 seconds'},
{:secs => 60 + 1, :string => '1 minute, 1 second'},
- {:secs => 60*2 + 1, :string => '2 minutes, 1 second'}
+ {:secs => 60*2 + 1, :string => '2 minutes, 1 second'},
+ {:secs => 60*60*2 + 60*2 + 1, :string => '2 hours, 2 minutes, 1 second'},
+ {:secs => 24*60*60*2 + 60*60*2 + 60*2 + 1, :string => '2 days, 2 hours, 2 minutes, 1 second'},
+ {:secs => 365*24*60*60*2 + 24*60*60*2 + 60*60*2 + 60*2 + 1, :string => '2 years, 2 days, 2 hours, 2 minutes, 1 second'}
].each do |data|
test "humanize #{data[:secs]} secs returns '#{data[:string]}'" do
assert humanize(data[:secs]) == data[:string]

0 comments on commit fc25f43

Please sign in to comment.