lucid icon indicating copy to clipboard operation
lucid copied to clipboard

Normalizing all dates

Open nanodracula opened this issue 8 years ago • 3 comments

Lucid currently normalize only default (created_at and updated_at) fields to 'YYYY-MM-DD HH:mm:ss'

But if we have some custom timestamp field like

table.timestamp('published_at')

and fill 'published_at' with something like 'new Date().toISOString()', Lucid doesn't normalize it to 'YYYY-MM-DD HH:mm:ss'.

Though If we fill 'created_at' with 'new Date().toISOString()' Lucid does normalize it.

I think formatting all timestamp fields to this default 'YYYY-MM-DD HH:mm:ss' would be more expected behavior... And docs tell us the same :)

Lucid formats all dates as YYYY-MM-DD HH:mm:ss by default, which is a valid format for all database engines.

nanodracula avatar Mar 14 '18 21:03 nanodracula

Hey @PazzaVlad! 👋

Have you defined the date into the model? http://adonisjs.com/docs/4.0/lucid#_dates

RomainLanz avatar Mar 15 '18 08:03 RomainLanz

oh, I don't know how I overlook that in docs :( Thanks) This solves the problem

  static get dates () {
    return super.dates.concat(['published_at'])
  }

nanodracula avatar Mar 15 '18 08:03 nanodracula

Cool! Closing then 😄

RomainLanz avatar Mar 15 '18 08:03 RomainLanz