I'm using mongoose and no matter what I tried, it overrides the stored dates' timezone.
I tried all of these defaults (one by one of course):
const ModelSchema = new Schema({
date: {
type: Date,
default: new Date().toLocaleString('en-US', { timeZone: 'Asia/Jerusalem' }),
default: moment.tz(Date.now(), 'Asia/Jerusalem'),
default: Date(moment.tz(Date.now(), 'Asia/Jerusalem')),
}
})
it seems mongoose runs new Date on whatever value I put there, because if I run this directly in node:
> Date(moment.tz(Date.now(), 'Asia/Jerusalem'))
'Sun Oct 03 2021 06:28:39 GMT+0300 (Israel Daylight Time)'
> new Date(moment.tz(Date.now(), 'Asia/Jerusalem'))
2021-10-03T03:28:42.217Z
what am I missing here?
I currently tested it only locally on my laptop