Why does DST affect addition/subtraction? #1639
-
I am new to Luxon coming from dayjs, which has the same behavior (allegedly, a bug). The code below produces different results when it's run in a time zone that observes DST: // luxon.js
const { DateTime } = require("luxon")
const date = DateTime
.fromISO("2024-06-04T10:51:36.135Z").plus({ days: 200 })
.toJSDate().toISOString()
//.toUTC().toISO() // same issue
console.log(date) "luxon": "^3.4.4" # Asia/Bangkok (Thailand does not observe DST)
$ date
Tue Jun 4 18:35:25 +07 2024
$ node luxon.js
2024-12-21T10:51:36.135Z # America/New_York (the US observes DST)
$ date
Tue Jun 4 07:35:46 EDT 2024
$ node luxon.js
2024-12-21T11:51:36.135Z My understanding is we're parsing an ISO 8601 date that's in UTC (ends with "Z"). So, in both cases we're operating on the same underlying date. We add 200 days. The outcome shouldn't change depending on where in the world we do the addition. I'm sure there's a reason why this happens, unless it's a bug. Can someone please explain? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can also pass |
Beta Was this translation helpful? Give feedback.
This is unfortunately not true, because days are not the same length everywhere due to DST changes. In the long run obviously they are, because DST "adds" an hour once a year and "removes" an hour once a year, but DST is observed at different times in the year.
Taking your example, when you add 200 days from now, Asia/Bangkok will not have observed DST, but on 2024-11-03 at 02 am America/New_York will set the clocks back by 1 hour. As such, the "200 days" will take one hour longer to complete in America/…