Skip to content

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

Closed
steveklabnik opened this issue Jan 21, 2015 · 9 comments
Closed

Create a more robust date/time crate #619

steveklabnik opened this issue Jan 21, 2015 · 9 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@steveklabnik
Copy link
Member

Issue by brson
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.

@jsanders
Copy link

Does chrono fulfill this? If not, what is missing?

@lifthrasiir
Copy link
Contributor

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.

@jsanders
Copy link

@lifthrasiir Gotcha. Is the idea that chrono would eventually be merged into the standard library?

@John-Nagle
Copy link

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.
"https://github.com/luisbg/rust-datetime" isn't packaged as a Cargo crate.
"https://github.com/rust-lang/rust/wiki/Lib-datetime" is discussion without any conclusions or actions.

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.

@brson
Copy link
Contributor

brson commented May 22, 2015

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.

IanWhitney pushed a commit to IanWhitney/xrust that referenced this issue Mar 6, 2016
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.
IanWhitney pushed a commit to IanWhitney/xrust that referenced this issue Mar 6, 2016
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.
IanWhitney pushed a commit to IanWhitney/xrust that referenced this issue Mar 6, 2016
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.
IanWhitney pushed a commit to IanWhitney/xrust that referenced this issue Mar 18, 2016
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.
@briansmith
Copy link

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:

  • Convert a time given in YYYY-MM-DD:HH:mm:ss[+ZZ:zz] components to a std::time::SystemTime.
  • Compare a < b ± ε, where a and b are SystemTimes.

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 time crate. But, I am curious if there is any interest in the Rust libs team in working towards some kind of standard API for this minimal functionality.

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.

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 18, 2016
@briansmith
Copy link

briansmith commented Aug 22, 2016

Compare a < b ± ε, where a and b are SystemTimes.

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 Tm struct to a SystemTime.

@briansmith
Copy link

briansmith commented Aug 22, 2016

So the only thing missing for certificate validation, at least, is a way to convert a Tm struct to a SystemTime

Actually, I was wrong about this too. As the documentation states, one can construct a Duration from a a Tm-like struct by converting YYYY-MM-DD:HH:mm:ss UTC to seconds and then using Duration::from_secs and then adding the Duration to std::time::UNIX_EPOCH. This can all be done in a platform-independent manner, since std::time::UNIX_EPOCH is required to be in UTC. Actually, I had previously written some C++ code (mozilla::pkix) that worked exactly that way! Here's a rough prototype of what is required for the conversion: briansmith/webpki@3f3cd95

Thus, the current state of things is fine for me. Sorry for the noise.

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

I think this issue has outlived its usefulness; no movement in 2 years and there are crates for this.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

9 participants