Hello rustaceans! Until recently, the time crate was soft-deprecated, in that bug fixes would be considered, but no features would be actively added. It is the 25th most downloaded crate all-time, and is still being downloaded slightly more than chrono. As such, I began a bottom-up rewrite of the time crate, taking inspiration from time v0.1, chrono, the standard library, and some RFCs, along with some localization pulled in from glibc.
My goal is to release time v0.2 alongside Rust 1.40, which is currently scheduled to be released on December 19. By going to the community for a public review now, this will allow me sufficient time to make any necessary changes.
To view the documentation for the master branch, you can use time-rs.github.io
. There are also some helpful shortcuts, so you can go to time-rs.github.io/Duration
and be brought to the relevant documentation immediately.
Follows are two pages from the wiki, which provide some detail as to what will occur in the future and the differences between existing crates.
Differences from chrono and time v0.1
Chrono has been the de facto crate for time management for quite a while. Like time, its original implementation predates rust 1.0. Presumably due to its age, chrono still relies on time v0.1 (though it's partially inlined the relevant code). The disadvantage of this is that any third-party functions that rely on chrono essentially mandate you import chrono or time v0.1 to use its Duration
type. This single fact makes interoperability with the standard library quite difficult. Time v0.1 is identical to chrono in this manner.
Time v0.1 is what the standard library was built upon. Time v0.2 flips this, being built upon the standard library. This provides for a higher-level abstraction, while also supporting the same targets as the standard library.
In time v0.2, there is full interoperability with the standard library. Every type can perform the same arithmetic that its standard library counterpart can and vice versa. Types are freely convertible to and from their standard library equivalents.
Vision
Scope
Most things that simplify handling of dates and times are in the scope of the time crate.
Some things are specifically not in scope.
- Nothing should implicitly rely on the system's time zone. Passing a time zone as a parameter or a function returning the time zone is acceptable. This restriction ensures that nothing surprising happens when running the same code on different systems.
Explicitly in scope, but not yet implemented include the following:
- Full timezone support, relying on tzdb.
Period
type, which would be usable with a zoned DateTime
. While this would expose a similar (if not identical) API to Duration
, the advantage is that it could take into account leap seconds, DST, etc. As such, a Period
would not be directly convertible to a Duration
- one minute could be either 59, 60, or 61 seconds.
Both lists are explicitly non-exhaustive. Additional items that are not in scope will be added to this list as they are brought up.
Strategy
Wherever possible, types are implemented as wrappers around those in the standard library. Additional functionality is still able to be provided, such as allowing a Duration
to be negative.
Some types (like Sign
) were helpful to implement generically, simplifying arithmetic implementations. They may be extracted to a separate crate in the future and re-exported in time.
Future plans
If all necessary reviews go well, my intent is to release time v0.2 shortly after the release of rust 1.40.
For post-v0.2 features, eventually I'd like to support tzdb, including automatic time zone shifts for DST and native leap second support. I'd also like to be able to have 5.seconds()
be able to return either a time::Duration
or std::time::Duration
, but the compiler is currently unable to infer the return type and choose the appropriate trait to use.
Let me know your thoughts, positive or negative. All I ask is that you be constructive and follow the code of conduct. I can be reached on Matrix either via direct message or on the #time-rs channel.
C-seeking-input π£