Thu Mar 27th
Copyright Rails Helper
# Pretty formatting of the copyright for the footer of your pages
module CopyrightHelper
def copyright(year, now=Time.now)
if now.year == year
year.to_s
elsif year / 1000 == now.year / 1000 # same century
year.to_s + "–" + now.year.to_s[-2..3]
else
year.to_s + "–" + now.year.to_s
end
end
end
if $0 == __FILE__
require 'test/unit'
class CopyrightHelperTest < Test::Unit::TestCase
include CopyrightHelper
def test_should_return_year_if_copyright_year_is_the_same
assert_equal "2000", copyright(2000, Time.local(2000))
end
def test_should_return_year_range_minus_century_if_the_same_century
assert_equal "2000–01", copyright(2000, Time.local(2001))
end
def test_should_return_full_year_range_if_different_century
assert_equal "1999–2000", copyright(1999, Time.local(2000))
end
end
end