-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create a more robust date/time crate #619
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
Comments
Does chrono fulfill this? If not, what is missing? |
cc me. @jsanders The current issue items for Chrono exactly list them. In particular, parsing and versatile time zone support is the next big thing. |
@lifthrasiir Gotcha. Is the idea that chrono would eventually be merged into the standard library? |
It's a good candidate for the standard library. Better than the other alternatives: "https://github.com/depp/datetime-rs" isn't packaged as a Cargo crate, so it's not importable. Chrono has most of what you need on the data format, calculation and output side. It lacks any string parsing functions. How much more effort should go into obscure time zone problems and leap seconds is not clear. We definitely need a standard representation of date and time in the standard library. Additional functions to operate on it can always be added. |
Just dropping this here http://www.reddit.com/r/rust/comments/36v4dz/practical_c_stl_concepts_and_ranges_the_calendar/ because the thread mentions something cool C++ can do with calendars. |
Adding the [Gigasecond exercise](http://x.exercism.io/problems/gigasecond) for the Rust track. This exercise is a little odd in Rust as the core language has no library for dealing with time. There was the Time crate, but that was pulled from the standard library. Based on [this RFC](rust-lang/rfcs#619) from last year, the Chrono crate appears to be the best current library for dealing with time. I've used Chrono here. Either because I'm still new to Rust, or because of an actual limitation in Chrono, the best way I could write the tests was to have everything be a UTC DateTime. This means that the tests that only use dates still require the slightly weird `.and_hms(0,0,0)` function at the end to make them DateTime-y. I did this because Chrono only seems to support Duration addition for DateTimes, not Dates.
Adding the [Gigasecond exercise](http://x.exercism.io/problems/gigasecond) for the Rust track. This exercise is a little odd in Rust as the core language has no library for dealing with time. There was the Time crate, but that was pulled from the standard library. Based on [this RFC](rust-lang/rfcs#619) from last year, the Chrono crate appears to be the best current library for dealing with time. I've used Chrono here. Either because I'm still new to Rust, or because of an actual limitation in Chrono, the best way I could write the tests was to have everything be a UTC DateTime. This means that the tests that only use dates still require the slightly weird `.and_hms(0,0,0)` function at the end to make them DateTime-y. I did this because Chrono only seems to support Duration addition for DateTimes, not Dates. I'm following the Ruby track example and putting this exercise after Hamming.
Adding the [Gigasecond exercise](http://x.exercism.io/problems/gigasecond) for the Rust track. This exercise is a little odd in Rust as the core language has no library for dealing with time. There was the Time crate, but that was pulled from the standard library. Based on [this RFC](rust-lang/rfcs#619) from last year, the Chrono crate appears to be the best current library for dealing with time. I've used Chrono here. Either because I'm still new to Rust, or because of an actual limitation in Chrono, the best way I could write the tests was to have everything be a UTC DateTime. This means that the tests that only use dates still require the slightly weird `.and_hms(0,0,0)` function at the end to make them DateTime-y. I did this because Chrono only seems to support Duration addition for DateTimes, not Dates. I'm following the Ruby track example and putting this exercise after Hamming.
Adding the [Gigasecond exercise](http://x.exercism.io/problems/gigasecond) for the Rust track. This exercise is a little odd in Rust as the core language has no library for dealing with time. There was the Time crate, but that was pulled from the standard library. Based on [this RFC](rust-lang/rfcs#619) from last year, the Chrono crate appears to be the best current library for dealing with time. I've used Chrono here. Either because I'm still new to Rust, or because of an actual limitation in Chrono, the best way I could write the tests was to have everything be a UTC DateTime. This means that the tests that only use dates still require the slightly weird `.and_hms(0,0,0)` function at the end to make them DateTime-y. I did this because Chrono only seems to support Duration addition for DateTimes, not Dates. I'm following the Ruby track example and putting this exercise after Hamming.
IMO, the chrono library is nice but it is too large to include in the standard library. I'd like to suggest that we create a library that allows for (just) the following:
These features are the minimum needed for many applications, in particular Web PKI X.509 TLS certificate validation. In the case of certificate validation, having a very narrowly targeted API, that can be exhaustively tested and/or even formally proved correct is very important. Additional features are a significant net negative. I believe a lot of functionality of a more full-featured crate like rust-chrono could be built on top of this. Right now, we can get that functionality from the time crate, but it is awkward because the time crate is deprecated, and so we look like we don't know what we're doing if we do that. But, switching to the chrono crate doesn't actually make anything better, because it itself depends on the time crate, so it's actually just adding complexity for the applications that need just this minimum functionality. I am thinking about creating a new crate that is just this functionality, probably by subsetting the I think it's good to focus on a very narrow API because it is truly an enormous amount of work to create something like the new C++ API or Java's (new or old) API, and I think it might be a long time before something like that becomes stable. |
If I undrstand correct, this is how one could compare a certificate's validity range to the current time: let now = SystemTime::now();-
let notBefore = <some way of constructing a SystemTime from its YYYY-MM-DD:HH:mm:ss[+ZZ:zz]>;
let notAfter = <some way of constructing a SystemTime from its YYYY-MM-DD:HH:mm:ss[+ZZ:zz]>;
/// XXX It would be better to do this by comparing the
/// YYYY-MM-DD:HH:mm:ss components pairwise.
if notBefore > notAfter {
return Err(...);
}
let epsilon = Duration::from_secs(60 * 60 * 24); // 1 day.
if now + epsilon < notBefore {
return Err(...);
}
if now - epsilon > notAfter {
return Err(...);
} So the only thing missing for certificate validation, at least, is a way to convert a |
Actually, I was wrong about this too. As the documentation states, one can construct a Thus, the current state of things is fine for me. Sorry for the noise. |
I think this issue has outlived its usefulness; no movement in 2 years and there are crates for this. |
Wednesday Jun 04, 2014 at 22:11 GMT
For earlier discussion, see rust-lang/rust#14657
This issue was labelled with: A-libs, I-enhancement in the Rust repository
Just clone JodaTime. Start out of tree.
The text was updated successfully, but these errors were encountered: