-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeZone GetNextTransition / GetPreviousTransition for far-future and far-past dates #60
Comments
Do you mean in this polyfill with this particular implementation of time zones, or in the proposal? I think the former is reasonable to do, in order to avoid DoS or just avoid terrible performance, for that matter. Note that @pipobscure wanted to make the time zone implementation in this polyfill pluggable at some point, so it's possible that people wouldn't generally use this inefficient time zone backend. In tc39/proposal-temporal#1370 I also made a proof of concept of loading the time zone data directly from the Olson data which performs much better than this loop. |
A "galloping" search could get this to something like O((log N)²). For example, exhaustively search for three years from the starting point, and if no transition is found then multiply the duration of each successive jump by the golden ratio (which should effectively sample subsequent years, cf. https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/#golden-ratio ). If a transition is encountered then repeat within the jump that found it, otherwise there is high confidence that no such transition exists. |
I mean polyfills. A native implementation should be designed with direct access to the underlying TZDB data, so there's no need for expensive iteration to handle this case. (Unless I'm missing something obvious.)
@gibson042 Galloping search PRs are always welcome! 😄 🏇 🐴 |
Meeting 2021-10-29: There's no silver bullet here without having access to the TZDB data, which would add a lot of bloat to the bundle size for client use. Consensus in the meeting was that we should deviate from the spec to prevent polyfill methods from taking an unreasonable amount of time. Thinking about the problem after the meeting, my suggestion is to do something like this:
|
The current implementation of TimeZone's
GetNextTransition
/GetPreviousTransition
methods behave poorly for very large or very small inputs, including possible denial-of-service issues caused by O(1) loops of expensive code.Examples:
There are a few issues here:
Should we simply limit future dates to N years in the future (N = 100? N = 50? N = 20?), and throw a RangeError for anything past that?
BTW, we already limit the problem for too-small dates (There was no DST before 1847 C.E.) when calling
GetPreviousTransition
. We should use the same smarts inGetNextTransition
to avoid Repro #2 above.The text was updated successfully, but these errors were encountered: