diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 99f2707..f33f6c3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -396,12 +396,20 @@ module ApplicationHelper # formats a date for displaying. def show_date(date) - date.strftime(_('%d %B %Y')) + if date + date.strftime(_('%d %B %Y')) + else + '' + end end # formats a datetime for displaying. def show_time(time) - time.strftime(_('%d %B %Y, %H:%m')) + if time + time.strftime(_('%d %B %Y, %H:%m')) + else + '' + end end end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 26783af..11f12bd 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -35,6 +35,10 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_equal 'translated date', show_date(date) end + should 'handle nil dates' do + assert_equal '', show_date(nil) + end + should 'translate time' do time = mock expects(:_).with('%d %B %Y, %H:%m').returns('the time') @@ -42,6 +46,10 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_equal 'translated time', show_time(time) end + should 'handle nil time' do + assert_equal '', show_time(nil) + end + protected def content_tag(tag, content, options) -- libgit2 0.21.2