Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add years counter to humanize helper

  • Loading branch information...
commit fc25f4366b7dd8066e26dae3a7232ee84cf6e7c3 1 parent 39dc768
@potomak potomak authored
View
2  app/helpers/application_helper.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
View
5 test/unit/helpers/application_helper_test.rb
@@ -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]
Please sign in to comment.
Something went wrong with that request. Please try again.