hook not recognizing "toLocaleDateString()"

I registered a little hook in data.js, as follows:
(‘auftragsDatum’ is a date field)
let dat;
export function auftraege__afterQuery(item, context) {
dat = item.auftragsDatum;
item.auftragsDatum = dat.toLocaleDateString();
return item;
}

Not only does it give the following Error when testing in preview,
but it weirdly also brakes the connection with the database, it’s not possible
to open the table, as long as this specific hook is registered in data.js.
The same goes for other JS-methods added to the hook,
only if I manipulate the string without built in JS-functions it works.

Someone from the WiX-Team should look into this, thanks.

You probebly have at least 1 item without an auftragsDatum value, that’s why it fails to apply the .toLocaleString().
In such cases, you cannot open the collection sandbox, because it runs the afterQuery() and gets an error.

Good point and valid, it resolved the problem. Thank you, sir (or madame)!

You’re welcome

If it works, it works. But doesn´t this give you the server locale and not the client locale?

The toLocaleDateString() method doesn’t give you any time. You provide a date to it either of your DB or whatever or you provide the current client date & time with “new Date()”