Hi everyone,
I’m working with Postgres/Sequelize and I’m facing a strange issue/behavior that I’ve been able to fix but that still remains strange.
My Postgres DB stores datetimes as ‘timestamps’, whenever I want to save a new date and time to my db through a SmartAction or SmartField, I do something like this:
myTable.lastUpdate = new Date()
await myTable.save()
Being based in France, I expect my date to be saved and displayed correctly on the front end with +02:00 timezone (Europe/paris for instance).
But every date is saved by default as +00:00 to my DB, so my dates always miss 2 hours.
I tried to set up the correct timezone on the project settings or let the browser default, but the issue remains.
My ultimate workaround was to add to config/database.js the following config:
const databaseOptions = {
logging: !process.env.NODE_ENV || process.env.NODE_ENV === 'development' ? console.log : false,
pool: { maxConnections: 10, minConnections: 1 },
dialectOptions: {},
timezone:"+02:00" // here
};
By default, Sequelize set this to +00:00 as mentioned here: Sequelize | Sequelize
Once I do that modification, my date now saves correctly to my DB, and the timezone in the project settings now automatically sets the date to the corresponding selected timezone or browser’s default.
Have you ever seen such strange behavior?
I feel like I shouldn’t use that timezone option to tell my DB how to correctly save dates, it should instead use UTC and display the correct date based on your timezone
Let me know what you think!
Simon