Skip to content

Commit

Permalink
Fix typo news date format with distance_of_time_in_words
Browse files Browse the repository at this point in the history
When a blog is configured with the distance_of_time_in_words
date_format, the typo news feed on the dashboard crashes because
new_js_distance_of_time_in_words_to_now assumes a Time object that
responds to #utc.  But the _typo_dev.html.erb partial passes a date
object, which does not respond to #utc.

It would make sense to format just the date, but then we'd need to
update the translations to handle the date-only format.  Or perhaps
we'd could call show_dates_as_local_time() on the page, which uses
the browser's locale's date format and makes the server-rendered date
mostly irrelevant.

For now, fix the crash by converting the parameter to_time before
formatting it.
  • Loading branch information
mcary committed Feb 5, 2013
1 parent 295b02c commit e092160
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def content_array
end

def new_js_distance_of_time_in_words_to_now(date)
# Ruby Date class doesn't have #utc method, but _typo_dev.html.erb
# passes Ruby Date.
date = date.to_time
time = _(date.utc.strftime(_("%%a, %%d %%b %%Y %%H:%%M:%%S GMT", date.utc)))
timestamp = date.utc.to_i
content_tag(:span, time, {:class => "typo_date date gmttimestamp-#{timestamp}", :title => time})
Expand Down

0 comments on commit e092160

Please sign in to comment.