Skip to content

Instantly share code, notes, and snippets.

@rlisowski
Created February 28, 2018 07:34
Show Gist options
  • Save rlisowski/7b97f3b75170fb1c01698bcc636f60f3 to your computer and use it in GitHub Desktop.
Save rlisowski/7b97f3b75170fb1c01698bcc636f60f3 to your computer and use it in GitHub Desktop.
Using date ordinals in Rails through an I18n time format.
# This goes in config/locales/en.rb (*not* en.yml)
{
:en => {
:date => {
:formats => {
:short => lambda { |date, _| "%b #{date.day.ordinalize}" },
:long => lambda { |date, _| "%B #{date.day.ordinalize}, %Y" }
}
},
:time => {
:formats => {
:default => lambda { |time, _| "%a, #{time.day.ordinalize} %b %Y %H:%M:%S %z" },
:short => lambda { |time, _| "#{time.day.ordinalize} %b %H:%M" },
:long => lambda { |time, _| "%B #{time.day.ordinalize}, %Y %H:%M" }
}
}
}
}
<%= l(Time.now, :format => :long) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment