moment-timezone old version caused date processing bugs during daylight saving time switch
I was using an old version of Moment Timezone and encountered a problem where UTC to PDT/PST conversion was bugged around the daylight saving time end date of November 6, 2016 (Sunday) 02:00 PDT.
As a result, the moment-timezone version I was using was old, so I resolved it by updating to the latest version.
When using the very old version 0.0.3, you can’t correctly get the end-of-day datetime for 2016-11-07 in the America/Los_Angeles timezone.
> var now = new Date("2016-11-09 17:30:00")
> var moment = require("moment-timezone")
> moment(now).tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-10 07:59:59'
> moment(now).subtract(1, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-09 07:59:59'
> moment(now).subtract(2, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-08 07:59:59'
> moment(now).subtract(3, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-06 07:59:59'
> moment(now).subtract(4, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-06 06:59:59'
> moment(now).subtract(5, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-05 06:59:59'
When using the latest version 0.5.9, it correctly gets the end-of-day datetime for 2016-11-07 as 2016-11-07 07:59:59.
> var now = new Date("2016-11-09 17:30:00")
> var moment = require("moment-timezone")
> moment(now).subtract(1, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-09 07:59:59'
> moment(now).subtract(2, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-08 07:59:59'
> moment(now).subtract(3, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-07 07:59:59'
> moment(now).subtract(4, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-06 06:59:59'
> moment(now).subtract(5, "days").tz("America/Los_Angeles").endOf("day").utc().format('YYYY-MM-DD HH:mm:ss')
'2016-11-05 06:59:59'
Since moment-timezone is IANA Time Zone Database + Moment.js library, version updates need to be done regularly to update the IANA Time Zone database to the latest.
Since I’m developing services for overseas, I feel like I’m regularly struggling with timezones…
That’s all from the Gemba.