-
Notifications
You must be signed in to change notification settings - Fork 546
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
Interoperability with hifitime for leap second support #198
Comments
I would recommend adding a The simplest way to do that would be to do something like: [dependencies]
chrono = { version = "0.4", optional = true } #[cfg(chrono)]
mod chrono_compat {
// all your conversion/compat items
}
#[cfg(chrono)]
pub use chrono_compat::*; Then your users can use your chrono compatibility layer by using If you run into any issues with chrono that make it unpleasant to use please open issues or pull requests! |
Details about chrono's leap second handling is documented in the Generally, chrono represents leap seconds as a nanosecond part of a Chrono parses strings with We don't track historic leap seconds, it's currently recommended to treat all timezones as TAI, rather than UTC. Honestly I haven't thought about this in great detail recently and I'm not sure how critical of a bug we should consider this. I don't believe that completely rewriting our internal time representation to use hifitime is in the cards, but improving our leap second support is enthusiastically desired. If you want to help us flesh out support in chrono I'd personally love it and be happy to work with you to make it happen. In return I can offer you nothing except for the thrill of contributing to one of the most depended-on crates in the rust ecosystem ;-) |
Thanks for the information and details. Let me start by trying to integrate chrono as an optional dependency (I didn't know those existed), and we can move on from there. Adding leap second support to chrono would be pretty awesome indeed. I started by doing an independent crate because it seemed easier to tackle than the beast-sized code base of chrono with its huge amount of features. I don't actually know how time is handled in chrono, but what I can say is that if there's a way to set a time reference at midnight on 01 January 1900, then adding leap second support from hifitime shouldn't be that hard. And, of course, I would be thrilled to work on that effort! |
What's the overall strategy that hifitime takes to implement leap second management? A cursory look at the code suggests that it's pretty similar to chrono (basically count the number of days since the epoch) except that chrono uses some tricks to optimize the calculation a bit more. Possibly just including the Leap second months in chrono would allow us to get leap seconds, but I'd much rather pull those leap seconds from the operating system if it's possible. And if we're pulling it from the tzdata files then that probably belongs in some interop with From another glance around the world:
So we're in good company not exposing leap seconds by default. Which makes sense, because we're not continuously broken all the time. Something that chrono would like to be able to do would be to grow the ability to handle multiple calendar systems (preferably by providing a basis for them so that they can be implemented in external crates), perhaps a leap-second-respecting calendar would be a good testbed. |
Leap seconds are announced usually on 28 December of a given year by the IETF. In recent years, there has been one leap second every other year on 31 December right before midnight of 01 January, cf. the official list of leap seconds. The strategy of You're right: almost no mainstream language supports leap seconds by default. In C, I usually rely on the NASA NAIF Leap Second "kernel" which needs to be loaded through the legacy-code of the SPICE Tookit. It's a real mess... And effectively, my desire to rewrite a number of SPICE features in rust (with Python scripting through C-FFI) led to me start hifitime. As someone who write simulation software, I actually see a lot of potential for Rust to enhance that field, and I think that a native Rust implementation of leap seconds would do a good poster child, especially if in the standard library or close to (i.e. either in std::time or in chrono given the ubiquity of chrono). Using the machine's time zone information to determine if a leap second has happened is valid, as long as the machine is synchronized with NTP (or a similar service). If not, it won't reflect the leap second change since these aren't predictable. Where can I find more information about chrono's plan to support multiple calendars? All I really need for my simulation software is leap second support if converting dates to and from UTC, and a specific calendar system called the Modified Julian Day. |
BTW, I agree that hifitime probably doesn't use as many short cuts as it should or could: I encountered a number of issues when implementing the conversion between UTC and number of seconds since TAI Epoch, so I do use quite a few loops for the conversion to make sure I don't forget anything: these can probably be simplified. The test suite is now exhaustive with specific odd time computation examples, so speed enhancements should be a focus of mine promptly. |
I'm quite new to Rust, and just wrote my first crate hifitime, which I will be using for precise time measurement calculations (which must include leap seconds) between TAI Epoch, UTC, and Julian days. I must admit that
chrono
has some pretty good timezone management and formatting possibilities, and it would take me some time to incorporate all that intohifitime
.Since I'm new to Rust, I was wondering what the best approach is here, and I am seeking advice from the chronotope team for this. Should I do one of the following (or something else entirely)?
hifitime
in the chrono dependencies and have the hifitime to chrono DateTime function exist in the chrono code base?Moreover, what will happen if I try to create a Utc datetime in chrono with
60
seconds?The text was updated successfully, but these errors were encountered: