Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Forked from Bodacious/datetime.rb
Created February 8, 2013 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertomartin/4741176 to your computer and use it in GitHub Desktop.
Save bertomartin/4741176 to your computer and use it in GitHub Desktop.
[Time, Date].map do |klass|
klass::DATE_FORMATS[:variable] = lambda do |t|
date =
case
# display today's date as "today"
when t >= Date.today then "today"
# display yesterday's date as 'Yesterday'
when (t >= Date.yesterday and t <= Date.today) then "yesterday"
# otherwise, display date: eg. Mon 4th June
else
t.strftime("%A #{t.day.ordinalize} %B")
end
time = t.strftime(" #{t.strftime("%I").to_i}:%M%p").downcase
date + time
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment