Skip to content

Instantly share code, notes, and snippets.

@crash2burn
Created September 5, 2008 22:09
Show Gist options
  • Save crash2burn/9037 to your computer and use it in GitHub Desktop.
Save crash2burn/9037 to your computer and use it in GitHub Desktop.
class DateTime
@@date_formats = {
:db => "%Y-%m-%d %H:%M:%S",
:time => "%H:%M",
:short => "%d %b %H:%M",
:long => "%B %d, %Y %H:%M",
:long_ordinal => lambda { |time| time.strftime("%B
#{time.day.ordinalize}, %Y %H:%M") },
:rfc822 => "%a, %d %b %Y %H:%M:%S %z"
}
alias :old_to_s :to_s
def to_s(format = nil)
return old_to_s unless format
self.strftime(@@date_formats[format.to_sym])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment