Date format are displayed 1 day earlier on forest.
event_date: {
type: DataTypes.DATEONLY, // Edited from DATE to DATEONLY
field: 'event_date',
},
In my db I store 2020-11-11, Forest gives me 2020-11-10.
Looking into this I noticed that forest prints my datetime 1 hour earlier than whats stored in db.
My theory is that forest converts date to datetime so when it gets 2020-11-11 it becomes 2020-11-11 00:00:00 but because it prints it 1 hour earlier it becomes 2020-11-10 23:00:00.
If I didnāt have this 1 hour delta I wouldnāt have notice that forest transform date to datetime.
Any hints to fix this?
Edit: the actual sequelize type for date only is DATEONLY. On the bulk view it only displays the date but on the record view it displays this 2020-11-10T22:00:00.000Z while its still 2020-11-11 in db.
I have no idea how to track it. Will the āTO DOā tag update itself when its done?
Definitely, the ticket should update once a member of the team starts working on this.
Any update on this?
I would love to help you find a temporary fix in the meantime. The one hour date difference looks like a timezone issue to me (But I might be wrong).
Edit: the actual sequelize type for date only is DATEONLY. On the bulk view it only displays the date but on the record view it displays this 2020-11-10T22:00:00.000Z while its still 2020-11-11 in db.
Did you try using the Date widget with a custom format ?
Itās definitely a timezone issue to me as well because using DATE it displays 2020-11-10 but using DATEONLY it displays 2020-11-10T22:00:00.000Z.
I donāt know where that 2hrs delay comes from but Iām pretty sure the system assumes 2020-11-10 is 2020-11-10 00:00:00 and minus the 2 hours gives 2020-11-10T22:00:00.000Z.
Here is my widget (the edit setting use the same custome format):
As a workaround (thank you for your patience ), maybe you could try to fix the date in your backend since there seems to be a problem with the Sequelize - MySQL - DATEONLY tuple.
According to this issue comment (thanks @jeffladiray for the suggestion), adding a get function in your model field could fix the issue (you may still need to adapt this code to be sure there is no timezone problem in it, according to your actual configuration):
One other option would be to use a smart field, but it could be considered overkill:
// In forest/orders.js file
collection('orders', {
fields: [{
field: 'fixedEventDate', // Sorry for the name
type: 'String',
get: (order) => {
return moment.utc(order.event_date).format('YYYY-MM-DD');
// Or something else that could fix the date: find the right conversion zone to apply.
}
}]
});
This is a kind of tinkering, but maybe it could help you in waiting for a fix. Feel free to ask if you are facing any problem.
As a side note: P3 is not our higher priority level, so it could take some time before it will be actually fixed. We try our best to fix all issues, but there are some priority rules. Thatās why we suggest a workaround for now.
the 2hrs delay issue (any idea where that could come from?)
Thanks, I didnāt think about creating a getter. It works now but I had to add 2hrs to the date to get the right date: moment.utc(this.getDataValue('event_date')).add(2, 'hours').format('YYYY-MM-DD')
If you could point where that 2hrs delay comes from it would be really helpful.
There seems to be some problems with timezones (Sources: 1, 2, 3, 4 and 5), they are always set even when it is not required.
You could also check the time returned by your server and the database, to understand where the -2h comes from. Maybe you could try to initialize moment with a default timezone corresponding to your configuration (e.g: require('moment').tz.setDefault(timezone)).
After reading these different issues and posts about sequelize and datetime, Iām guess the problem is in Sequelize itself (and its environment). Forest Admin seems to not override the values at this moment. I may b wrong though.
What seems still strange to me is that moment.utc should be good. Could you check with a console log in your server?
const value = moment.utc(this.getDataValue('event_date')).format('YYYY-MM-DD h:mm:');
console.log(value);
Yes itās still wrong, I get 2020-11-02 10:00: while itās 2020-11-03 in my db.
What I did is I edited the date from forest picking 2020-11-03, I stores 2020-11-03 in the db but retreiving it gives me 2020-11-02 10:00:.
Yes itās still wrong, I get 2020-11-02 10:00: while itās 2020-11-03 in my db.
I guess itās a problem with the date-time of your server then: if moment returns you a wrong UTC time when you explicitly ask for UTC, it seems it is not aware of the actual date-time. Let me know if you find a solution
In /models/index.js I add the line timezone: '+02:00' somehow.
So my event_date displays correctly now, I just need a getter because of the sequelize issue: return moment(this.getDataValue('event_date')).format('YYYY-MM-DD')
My timestamps are 1 hour ahead though now, they were 1 hour late. Itās not a big deal for me at the moment. Iāll look into it later.