Parse Date, timezone problem because Z is removed
roelandmoors opened this issue · 2 comments
roelandmoors commented
There is a sanitiser that removes the Z from a date:
database-js/src/sanitization.ts
Line 47 in c0159c5
But when I parse that string back to a date I get the wrong result. I needed to add the Z back to make it work:
new Date(Date.parse(d + "Z"));
I had that problem here:
https://github.com/roelandmoors/authjs-adapter-mysql/blob/5867a205154f91c88086c0ce2a5101e79c61faf7/src/db.ts#L45
Seems like a bug to me?
roelandmoors commented
I now have a Date to string conversion like below. This way the Z can be stripped without a problem.
export function datetimeToStr(d) {
const tzoffset = d.getTimezoneOffset() * 60000; //offset in milliseconds
return new Date(d.getTime() - tzoffset).toISOString().slice(0, -1);
}