-
Notifications
You must be signed in to change notification settings - Fork 542
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
Future of leap second handling #954
Comments
Option 1: change nothing |
Option 2: count leap seconds as seconds=60, nanoseconds<1B |
Option 3: assume the host clock is UTC-SLS, remove leap second support from chrono |
Option 4: like option 3, but also introduce a leap second table (potentially fetched from the system) to compute durations |
Option 5: introduce a TimePoint type, counted in TAI, that can convert from/to DateTime (probably in addition to option 2) |
Option 6: like option 5, but make struct DateTime(TimePoint, Tz) |
I don't think I will have time to digest this in the near future, sorry. |
No problem! I tried to make the top-post as easy to digest as possible and requiring no context so it's possible to read it without knowledge of the past discussions and understand the tradeoffs, so it shouldn't be harder to read later with less context. I just hope you get a chance to look into it long enough before releasing chrono 0.5 that I can get a chance to try and implement the required things to get them in, if 0.6 is another 5+ years down the road :) |
@Ekleog Thank you so much for digging into this issue! And you put your money where your mouth is with your kine crate. As a first note: while I personally think leap seconds are cool (I love exotic little complexities like this), most library code really doesn't want to think about leap seconds. If code adds My opinion on your options:
What I would propose is:
|
Adding a |
This feels like the core of issue to me: what is the meaning of I'm sure you're all very aware of this, but there is not a single definition of what is a "second" and this is the root of this problem:
The duration of a mean solar day is 86,400 historical seconds by definition, but 86,400.0013 SI seconds by measurement. Calendars try to remain in sync with solar days and the discrepancy between both units (SI and historical) is what ultimately leads to leap seconds. (and the differences between UTC/TAI/UT1/UT2, ...) UTC uses SI seconds but tries to approximate historical seconds by introducing discontinuities through leap seconds. What I find disappointing is that instead of containing this complexity to the conversion between a timestamp measured in SI seconds and a calendar representation, we instead ended up with timestamps measured in historical seconds. The current situation feels like an unhappy middle-ground: duration computations with timestamps are broken and you still have to go through timezones for display anyway. But retro-compatibility trumps all :/ (Sorry for the long preface, but I really feel that framing the issue as a unit problem is a helpful perspective) This brings me back to the meaning of adding In general, I feel that this situation is similar to the difficulties around Unicode. Rust requires users to be somewhat aware of the related complexity. Time and calendars are also seemingly simple but get pretty complex, and I hope that chrono helps with providing clearer semantics. I would strongly prefer if options 5 or 6 were supported by Chrono; and a |
Well written, the complexities of reality that do not perfectly fit a clean mathematical model 😄.
@demurgos #1282 is about creating a new |
I'm writing this issue to try and summarize all the possibilities for leap seconds handling in chrono, hopefully this will help making a decision :) (I can't find a checkbox to allow edits by maintainers, so feel free to ping me if you want anything added here!)
Option 1: change nothing
The current behavior has the following problems:
Option 2: count leap seconds as seconds=60, nanoseconds<1B
Pros:
Cons:
:60
seconds, which is likely to crash other consumersOption 3: assume the host clock is UTC-SLS, remove leap second support from chrono
Pros:
Cons:
As a further idea, to mitigate the "what if the host clock is actually UTC" issue, we could reserve the last microsecond of each minute to store milliseconds in case of a leap second. This would make time flow like:
Note that this would have to happen during the 59th second of each minute, as it's hard to predict whether the host clock is actually running UTC-SLS or not, and whether there is going to be a leap second if not.
However, chrono would then keep in normal times the property that it returns time precise to the microsecond (which is the case on windows), and would just lose one microsecond of precision once a minute to avoid times too far apart from becoming exactly-equal values in the case of a leap second
Option 4: like option 3, but also introduce a leap second table (potentially fetched from the system) to compute durations
Pros:
Cons:
TBH, IMO this is definitely not a good solution, we should pick another option. I'm having it here for completeness.
Option 5: introduce a TimePoint type, counted in TAI, that can convert from/to DateTime (probably in addition to option 2)
Pros:
Cons:
Overall, I think the con is not actually a downside. It hits basically the same problem as regular timezone rule changes, that happen almost as regularly as leap second insertions: since 2012 (start of the iana archives), there has been 3 leap seconds, and 86 tzdata changes, so at least 83 timezone changes that were recorded.
I think if chrono can stomach being probably at least one hour off half the year at 83 places, then it can probably stomach being 3 seconds off. And if it cannot, then tzdata should be provided by the OS and not hardcoded in chrono, which would fix both issues.
Option 6: like option 5, but make
struct DateTime<Tz>(TimePoint, Tz)
Pros:
- Like option 5, plus
Cons:
DateTime
with a leap second in the future that chrono does not know about, even if the user were to know about it.For full disclosure, I'm personally partial towards option 6, based on the pros and cons listed above.
What do you think?
For people who may want to express their opinion about which ideas they think are good/bad without adding new information to the debate, I'm going to add one message per option, feel free to up/downvote (keeping all options in the top-post so that maintainers can hopefully edit it)
The text was updated successfully, but these errors were encountered: