Date and Time Formats for Pirates

Need to display a date in your Rails app? First try:

Time.now.strftime "arrrround %H'ish"

To remove duplication, you imagine a time format initializer. Second try:

Time.now.to_s :pirate

Then you remember the :default localized key. Third time’s a charm:

l Time.now

It formats based on the config/locales/en.yml file:

en:
  time:
    formats:
      default: "arrrround %H'ish"
  date:
    formats:
      default: "arrrround %H'ish"

Dates work, too:

l Date.today

The same system lets you alter the display of “days ago” and “minute from now.”

Alex Berry