Administrate: DateFormat Option in Field::DateTime

Created on 14 Dec 2016  路  5Comments  路  Source: thoughtbot/administrate

I found a few possible options for fields in the Docs, added in #647.

Unfortunately, no option for date formatting seems to be supported yet. Is this not possible yet or just missing from the docs?

If it is no possible yet, I'd be happy to try my hand in adding this.

bug

Most helpful comment

In the index page, I am getting "00:00:00" in the time part of the DateTime for every record when I do this (in config/locales/en.yml):

date:
  formats:
  default: "%d/%m/%Y %H:%M:%S"
time:
  formats:
    default: "%d/%m/%Y %H:%M:%S"

or this (in the dashboard):

created_at: Field::DateTime.with_options(format: "%d/%m/%Y %H:%M:%S"),

It works fine on the show page.

All 5 comments

@fogshot It's possible, albeit in a limited way, to format the date through i18n: if you set date.formats.default or time.formats.default then this will control how dates and times are formatted, at least on index and show pages.

In the index page, I am getting "00:00:00" in the time part of the DateTime for every record when I do this (in config/locales/en.yml):

date:
  formats:
  default: "%d/%m/%Y %H:%M:%S"
time:
  formats:
    default: "%d/%m/%Y %H:%M:%S"

or this (in the dashboard):

created_at: Field::DateTime.with_options(format: "%d/%m/%Y %H:%M:%S"),

It works fine on the show page.

I can see that it is calling date on the field in the index view and datetime in the show view. Was this intentional? Kind of largely defeats the idea of setting the format.

Hi @mark100net! That sounds like a bug. Do you think you'd be able to open a PR for that?

@nickcharlton I will try to get to it this weekend.

Was this page helpful?
0 / 5 - 0 ratings