How does Luxon abuse the Intl API? #1370
-
The Why does Luxon Exist Readme says the Intl API is horribly abused in order to make the time zone handling work. How exactly? I assume this abuse is how we're able to obtain a timestamp at an arbitrary timezone (potentially different from local time zone and UTC). I'm curious about the cleverness, but also wondering how fragile this is. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It's not fragile at all, but it has a few limitations, such as handling historical zones that have fractional-minute offsets, and likely hypothetical time zones where the offset shifts multiple times in quick succession. It's also unlikely to be a relevant use case for performance optimizations that browsers make to the Intl API. The abuse is that the Intl API will return a structured output (see formatToParts) which can be used to calculate the current offset with a bit of logic. Here is a detailed answer I gave explaining that logic, as part of answer to how someone could, hypothetically, detect ambiguous local times: #1018 (comment). |
Beta Was this translation helpful? Give feedback.
It's not fragile at all, but it has a few limitations, such as handling historical zones that have fractional-minute offsets, and likely hypothetical time zones where the offset shifts multiple times in quick succession. It's also unlikely to be a relevant use case for performance optimizations that browsers make to the Intl API. The abuse is that the Intl API will return a structured output (see formatToParts) which can be used to calculate the current offset with a bit of logic. Here is a detailed answer I gave explaining that logic, as part of answer to how someone could, hypothetically, detect ambiguous local times: #1018 (comment).