The following block doesn't work as we expected.
function getNonDstTimeZoneOffset(date) {
const january1st = new Date(date.getFullYear(), 0, 1)
const july1st = new Date(date.getFullYear(), 6, 1)
return Math.max(january1st.getTimezoneOffset(), july1st.getTimezoneOffset())
}
//january1st.getTimezoneOffset() = 480 (should be -540...)
//july1st.getTimezoneOffset() = 420 (should be -480? though we don't have DST...)
function resetDateWithCurrentTimeZone(utcDate) {
if (!utcDate) {
utcDate = new Date()
//EX) "2023-11-20T07:03:29.492Z"
}
const timezoneOffset = utcDate.getTimezoneOffset()
const nonDstTimezoneOffset = getNonDstTimeZoneOffset(utcDate)
log.audit("==UTCDate & LocalOffset==", {
utcDate: utcDate,
timezoneOffset: timezoneOffset, //480
//Why is not it -540?
nonDstTimezoneOffset: nonDstTimezoneOffset //480,
//Why is not it -540?
})
if (timezoneOffset && nonDstTimezoneOffset) {
return changeTimeZone(utcDate, nonDstTimezoneOffset)
}
return utcDate
}
Our timezone is Asia/Tokyo GMT+9:00, and the data center is Australia/Melbourne.
There are mainly 2 wierd points.
- The returned value should be a negative number, -540.
- Why it returns 480 not 540 though even 540 is still wrong.
In the NS the data object behaves differently from the normal JS environment?
From which time does getTimezoneOffset take the gap in the NS?
(From server center's time, user's client machine, or whatever... I'm completely lost about the specification because of the above return values...)