A datetime library for Rust

15 points by refi64 an hour ago on lobsters | 4 comments

simonw | an hour ago

Jiff is pronounced like “gif” with a soft “g,” as in “gem.”

That's very funny.

As a Go developer, can someone explain to me why this is not part of Rust's standard library? This is not a criticism, I know languages have different philosophies, I'd just like to understand better the rationale for not adding things like datetime, random, base64, etc. to the standard library. I know finding a definite design is hard and once it's committed to the standard library, it's forever, but wouldn't it be better for the ecosystem to rely on an official (or at least officially blessed, like letting jiff live as a separate repo but part of the Rust Foundation) implementation for basic building blocks? I know I always get a particular thrill when something is added to the Go stdlib and I can remove an external dependency (HTTP router improvements, or UUIDs for the last examples I have in mind)

burntsushi5 | 29 minutes ago

An early version of the time crate actually used to be shipped as part of the Rust distribution prior to Rust 1.0. That's ancient history now, but we explicitly kicked it out of the distribution because we knew it was a huge and complex domain whose modeling is difficult to get right. What if we had standardized on it? No good. What if we waited a few years and standardized instead on chrono? Still no good. (You can see more of my thoughts on why in Jiff's comparison and design documentation.)

It really wasn't until the Temporal folks invested many person years of effort into modeling the domain that I think we've arrived at a real nice answer to the question of, "How does one design a datetime library?" But that only happened recently. Jiff really wouldn't be what it is without it.

Is Jiff the final answer? Who knows. 1.0 was just released. It's already used in production across many applications, but we'll see what happens as more folks adopt it.

Also, Jiff is way bigger and more complex than Go's standard library time package. By an order of magnitude at minimum. There are lots of reasons for this:

  1. Jiff has a stronger focus on using types to prevent domain errors. Go's time.Time is like a jiff::Timestamp combined with some kind of ZonedDateTime.
  2. Rust APIs are usually inherently more complex because of its approach to polymorphism and because their tends to be a stronger cultural focus on performance.
  3. Go has only one basic duration type. Jiff has a similar duration type but also a Span that combines calendar and physical time units all into one type.
  4. Jiff support civil time. Go's time package doesn't support this at all.

There's probably more stuff too. But that's from a quick look (and memory, since I used to use Go a lot).

In principle it would be nice for something like Jiff to be in std. But its API surface area makes it a huge risk. I don't want to release Jiff 2.0, but I can if the need really arises.

What if we had standardized on it? No good. What if we waited a few years and standardized instead on chrono? Still no good.

I don't know how/if deprecations live in Rust's stdlib, but could something like datetime -> datetime::v2 -> datetime::v3 have been useful for the ecosystem as a whole? Even if they end up being deprecated, they still exist forever in the stdlib and a clear migration path could be made possible (like Go did with encoding/json -> encoding/json/v2)

Jiff is way bigger and more complex than Go's standard library time package

Yeah, the comparison was not the best, it indeed covers a lot more than Go's time. I guess it's more of a general question regarding "basic" (in the sense of "expected", not that they're necessarily easy to implement) building blocks: maybe Jiff would be to big to add to Rust's stdlib (although Temporal is somewhat part of JS stdlib haha) but I'd imagine some more "bare" version, or some types/traits would make sense as a standard