Skip to content

Instantly share code, notes, and snippets.

@codatory
Created June 14, 2012 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codatory/2927480 to your computer and use it in GitHub Desktop.
Save codatory/2927480 to your computer and use it in GitHub Desktop.
# Date formats
Time::DATE_FORMATS.merge!(
:friendly_date => lambda {|d| "#{d.month}/#{d.mday}" }, # 4/25 (no leading zeroes)
:friendly_time => lambda {|t|
date = (t.at_midnight == Time.now.at_midnight) ? '' : "#{t.month}/#{t.mday}@" # 4/25@4PM on other days
"#{date}#{t.strftime('%I').to_i}#{t.strftime('%p')}" # 4PM on same day
},
:year => "%Y", # 2008
:month_year => "%b %Y", # Apr 2008
:ampm_time => "%I:%M %p", # 04:15 PM
:two_digit_year => "%y", # 08
:period => "%Y-%m", # 2010-04
:basic => "%b %d %y", # Apr 25 08
:db_date => "%m-%d-%Y", # 04-25-2008
:slashy_date => "%m/%d/%Y", # 04/25/2008
:short_slashy_date => "%m/%d/%y", # 04/25/08
:short_db_date => "%m-%d-%y", # 04-25-08
:short_day => "%b %d", # Apr 25
:short_day_no_space => "%b%d", # Apr25
:short_day_time => "%b %d %I:%M %p", # Apr 25 04:15 PM
:short_date => "%b %d %Y", # Apr 25 2008
:short_datetime => "%b %d %Y %I:%M %p", # Apr 25 2008 04:15 PM
:picker_datetime => "%b %d %Y %H:%M", # Apr 25 2008 04:15
:full_date => "%B %d %Y", # April 25 2008
:abbr_datetime => "%m/%d %I:%M %p", # 04/08 04:15 PM
:verbose_datetime => "%B %d, %Y at %I:%M %p", # April 25, 2008 at 04:15 PM
:slashy_datetime => "%m/%d/%Y %I:%M %p", # 04/25/2008 04:15 PM
:dashy_datetime => "%m-%d-%Y %I:%M %p", # 04-25-2008 04:15 PM
:day_name_datetime => "%a, %b %d, %Y at %I:%M %p" # Fri, Apr 25 04:15 PM
)
Date::DATE_FORMATS.merge!(Time::DATE_FORMATS)
@veloper
Copy link

veloper commented Jun 14, 2012

:db => "%Y-%m-%d %H:%M:%S",
:number => "%Y%m%d%H%M%S",
:time => "%H:%M",
:short => "%d %b %H:%M",
:long => "%B %d, %Y %H:%M",
:long_ordinal => #<Proc:0x007ffa31fd3bc0@/Users/DDoezema/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.6/lib/active_support/core_ext/time/conversions.rb:12 (lambda)>,
:rfc822 => #<Proc:0x007ffa31fd3af8@/Users/DDoezema/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.6/lib/active_support/core_ext/time/conversions.rb:13 (lambda)>

@veloper
Copy link

veloper commented Jun 14, 2012

^^ Rails Defaults

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment