Is anyone else having new problems with dates in their Wix Code? I have code that has been working flawlessly for over a year and recently it is not working correctly. All of the challenges seem to be around dates. The dates are pulling incorrectly from my database, not ‘adding’ days correctly, and not assigning correct values to date pickers.
For example,
$w("#clientUpdates").onReady(() => {
wixData.query('ClientUpdates')
.eq("userCode", userId)
.descending("_createdDate")
.find()
.then(maresults => {
let maresultsCount = maresults.totalCount;
if (maresultsCount > 0) {
let updateDue = maresults.items[0].nextUpdateDue;
console.log("Next Update:" + updateDue);
$w("#firstDate").value = updateDue;
$w("#nextUpdate").text = updateDue.toLocaleDateString();
let lateDate = maresults.items[0].nextUpdateDue;
lateDate.setDate(lateDate.getDate() + 1);
console.log("Late: " + lateDate);
let missedDate = maresults.items[0].nextUpdateDue;
missedDate.setDate(missedDate.getDate() + 7);
console.log("Missed: " + missedDate);
console.log("Date in ClientUpdates " + updateDue);
In this code snippet, I query my client updates and find the most recent update. I pull the date of the most recent update (maresults.items[0].nextUpdateDue) and assign it variable updateDue
If you notice, I take the updateDue variable and use it to create two other variables: lateDate and missedDate. lateDate is 1 day past the updateDue date and missedDate is 7 days past the updateDue date.
So, for example, if updateDue is November 9, 2020, lateDate should be November 10, 2020 and missedDate should be November 16, 2020.
However, my console log looks like this:
Next Update: Mon Nov 09 2020 00:00:00 GMT-0500 (Eastern Standard Time)
Late: Tue Nov 10 2020 00:00:00 GMT-0500 (Eastern Standard Time)
Missed: Tue Nov 17 2020 00:00:00 GMT-0500 (Eastern Standard Time)
Date in ClientUpdates Tue Nov 17 2020 00:00:00 GMT-0500 (Eastern Standard Time)
You can see, it’s as if it does not see three separate variables but just one and it keeps adding days to the previous variable, regardless of the fact that the variables are different. And by the end, the updateDue variable has evolved from November 9 to November 17.
Also, the $w(“#firstDate”).value (date picker) shows up as November 17 while the $w(“#nextUpdate”).text (textbox) shows up as November 9.
Any ideas why this would suddenly be happening?