Date and Time Formats for Pirates

Alex Berry

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.”

We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.