British date formatting with Rails

ruby rails helpers date datetime activesupport

Thu Apr 16 12:34:58 +0000 2009

Here’s a little helper for UK Rails users when formatting a Date or DateTime object in your view.

I looked around for quite a while before I discovered the term ‘ordinalize’, so I hope this helps someone. Dates can be so America-centric sometimes (no hard feelings, State–side homeboys).

def nice_date(date)
  # formats date like: 30th September 2009
  date.strftime("#{date.day.ordinalize} %B %Y")
end

I’ll refine this one soon…

def fake_tv_northerner(text)
  text = "t'".concat(text)
end
blog comments powered by Disqus