Sudden error in 1 year old function

On a dynamic page that has been running for a year, I suddenly get the error:

An error occurred in one of datasetReady callbacks TypeError: myDateIn.getDate is not a function
at convertLongDate

This is the function, very old, and the editor doesnot flag .getDate() as wrong, nor do I see any error.

function convertLongDate(myDateIn) {
let thisDay = myDateIn.getDate();
let strthisDay = “0” + thisDay.toString();
strthisDay = strthisDay.substr(strthisDay.length - 2, 2);
let thisMonth = myDateIn.getMonth() + 101;
let strthisMonth = thisMonth.toString();
strthisMonth = strthisMonth.substr(strthisMonth.length - 2, 2);
let thisYear = myDateIn.getFullYear();
let formattedDate = strthisDay + “/” + strthisMonth + “/” + thisYear;
return formattedDate;
}

Anyone?

It gets weirder: I put some logging in like so:

   datValidFrom = $w('#ddsPropsVIew').getCurrentItem().ptValidFrom; 

console.log(" datValidFrom=" + datValidFrom);
console.log(" type datValidFrom=" + typeof datValidFrom);

And in Publish Mode (not Preview) I get this:

datValidFrom=2018-07-01T03:00:00.000Z
console.js:35 type datValidFrom=string

And no, I did not declare it as a string in the Collection.

Hi, Giri.

While you were typing that last message, I was composing the following:

“Since the function hasn’t changed, what about the parameter you’re passing in (viz., myDateIn); is that no longer what you expect it to be (viz., something that has a getDate function)?”

Art

It happens everywhere, in EVERY page ever made: Dates from the DB (defined as dates in Collection) are consistently retrieved as type string. This is a huge problem for me.

Can anyone confirm this behaviour?

Let me refine the above. It happens like this:

  1. if you retrieve a field (declared as type “Date & Time” in Collection with getCurrentItem(), the field is retrieved in Preview Mode with data type “object” (correct) and in Publish Mode with data type “string”
  2. it happens 9 times out of 10 (so 1 out of 10 I get “object”, not string);

Proof

Code (partial):

let datEndDiscount = $w(‘#ddsPropsVIew’).getCurrentItem().ptValidThru;
console.log(“type datEndDiscount=” + typeof datEndDiscount );
console.log(“type ptValidThru=” + typeof $w(‘#ddsPropsVIew’).getCurrentItem().ptValidThru );

In Preview Mode:

In Publish Mode:

Solved it temporarily with this workaround (if anyone else run into it):

function fnCheckDataTypeForStringBug(datAnyDate) {
// 03/09/2018 workaround for bug that returns a Date as a String in Publish Mode. If it is one, convert it to Date type
let thisNewDate
if ( typeof datAnyDate === “string”) {
thisNewDate = new Date(datAnyDate)
} else {
thisNewDate = datAnyDate;
}
return thisNewDate;
}

Was something changed in Wix that caused this issue?

(On a side note, if you replace “03/09/2018” with “2018-09-03” in your comment, then those of us in the United States will know that you implemented the workaround on September 3, 2018 and not on March 9, 2018.)

@abergquist : Yes, if you have not made love to your wife for over a year and she is suddenly pregnant, it would be within reason to suspect the cause of the new situation to be within her realm of responsibility, not yours.
About date format in comments: point taken, should have done that.

WRT your first comment, I’ve heard of spontaneous combustion but not of spontaneous pregnancy