Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default date formatter in active admin

In ActiveAdmin dates are printed in the, supposedly American, format %B %d, %Y %H:%M. E.g. March 19, 2013 13:25

However, my "default" frontend prints this using the default Rails (ISO) format, 2013-03-07 14:12:31 UTC, as seen when dropping a <%= Date.new %> anywhere in a view.

  1. What is defining the format for the ActiveAdmin dates?
  2. Where or how can this be changed, if possible, simply following a global Rails wide i18n setting.
like image 886
berkes Avatar asked Mar 19 '13 14:03

berkes


People also ask

What is active admin?

Active Admin is a framework for creating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort.


2 Answers

please, ensure you have next lines in your config/locales/en.yml

en:
  date:
    formats:
      long: "%Y-%m-%d"
  time:
    formats:
      long: "%Y-%m-%d %H:%M:%S"

Also if you want to change Filter default date formats Try this Active Admin date filter date format customisation

like image 118
Fivell Avatar answered Sep 28 '22 11:09

Fivell


What is defining the format for the ActiveAdmin dates?

From the Localize Format For Dates and Times section of the configuration docs:

Active Admin sets :long as default localize format for dates and times.

Source: General Configuration - Localize Format For Dates and Times.

Where or how can this be changed, if possible, simply following a global Rails wide i18n setting.

From ActiveAdmin v1.0.0.pre2 you can override the default localize_format configuration to use a different format:

ActiveAdmin.setup do |config|
  config.localize_format = :short
end

Alternatively you can update the :long format in your locales configuration as suggested by Fivell:

en:
  date:
    formats:
      long: "%Y-%m-%d"
  time:
    formats:
      long: "%Y-%m-%d %H:%M:%S"
like image 20
Giovanni Cappellotto Avatar answered Sep 28 '22 13:09

Giovanni Cappellotto