Jiff 1.0: A datetime library for Rust

(burntsushi.net)

258 points | by burntsushi 6 hours ago ago

56 comments

  • quodlibetor 4 hours ago

    I maintained chrono for about half a decade, and the specific reason I took on maintenance was because the API sucked and I hoped I could make it better.

    Turns out, the reason people wanted to use it was because the API was stable and every slight step towards improvement was met with... resistance. I stopped maintaining it because the burnout from seeing what it could be and not seeing any path to get there was too much for me.

    I'm extremely grateful to burntsushi for writing the datetime library rust deserves. Chrono is stable and is maintained (though semi-deprecated) by an extremely reliable rustacean -- you don't need to leave, but you'll probably be happier if you do.

    • lifthrasiir 2 hours ago

      As the original author of Chrono, thank you so much for your service. It was always a learning experience for me to design and maintain Chrono (that's why the API is not very good, despite my best efforts) and I too had been burnt out from doing so, so it was fortunate that the right people stepped up and kept the torch burning for so long time.

      • the__alchemist 42 minutes ago

        Thanks to you both. I am giving benefit of doubt to those saying Jiff is even better, and I am trying Jiff today, but make no mistake: Chrono is by far, the best datetime library I've used. If Jiff ends up being people's #1, I hope they realize that Chrono is probably the #2 of any datetime library in existance. Thank you so much. It is dramatically better than Python's and JS's (official and unofficial) ones. I can rely on it for std and embedded tasks, and trust it to act as I expect.

    • Arch485 2 hours ago

      I'm really curious - what makes you say chrono's API sucks?

      I've used it in several projects, and to me it seems just fine. Granted, I don't do a lot of cross-time zone work; I exclusively use UTC whenever possible.

    • steveklabnik 3 hours ago

      Thanks for helping maintain Chrono. Burnout is the worst, I hope you're feeling better these days.

    • ddahlen an hour ago

      Thanks for maintaining such a core tool, it has been really helpful for me!

    • burntsushi 3 hours ago

      <3

    • joel2oliver an hour ago

      Thanks. I shipped a couple of things on chrono and never had to think about it. That was you.

  • Dagonfly 4 hours ago

    > When should I use Jiff? Jiff isn’t always the right thing to use.

    I really appreciate when a project calmly acknowledges that it's not the right tool for every use case, and is not trying to be. That's professional engineering.

    Especially in the AI-age, the crucial skill will be what NOT to implement.

  • mgrandl 5 hours ago

    It’s so good like all the other burntsushi libs. Really hope it will be adopted more and more by the wider ecosystem over chrono and co.

    • dicke 4 hours ago

      He is incredibly kind and gracious too. I've made some contributions to jiff, and Andrew is so easy to work with.

      • AeroNotix 3 hours ago

        Andrew had a pretty decent impact on the course of my career and I doubt he even remembers it or even thought of it as an act of good he did.

        In the very early Go days (<0.9) he responded to a comment of mine going into why Go was worth looking into, quite passionately and enthusiastically which set me off on learning it and where it could be applied and that changed the kinds of roles I went after.

        Ever since it's a bright little nugget whenever I see his name pop up and have tried to follow his work ever since.

        • burntsushi 2 hours ago

          Wow, I don't remember that! I'm happy to have had that impact. :-)

  • ddahlen 4 hours ago

    This looks interesting!

    Time is such a pain, I write code for simulating orbits of asteroids/stuff in the solar system, and time and time conversions play a major roll in it. I often need accuracy at the mega-year to giga-year scales, but also sometimes micro-second relative.

    I saw on this page that you at least mention TAI time, how are you handling time scales in general? Like would it be hard to add some other timescales like UT1?

    Right now I have to do all of this manually and I have been using chrono as just a convenience wrapper so that my users can convert ISO time strings into my internal representation.

    Edit: Oh no! I just found out chrono is being semi-deprecated, looks like I'm going to be switching...

    • burntsushi 4 hours ago

      Jiff only supports the Unix time scale. It sounds like you probably want `hifitime` instead! I believe it was designed with your use case in mind. See: https://docs.rs/hifitime/

      • ddahlen 4 hours ago

        Thanks for making useful tools!

        Ah yeah hifitime, I tried it out but its internal representation doesn't work well for my long term simulations, the integer representation ends up increasing the numerical noise in my simulations when I do really sensitive long term ones.

  • the__alchemist 4 hours ago

    I will give this a shot, however... Rust is the only language I've used where I want to use the established one, chrono. I will roll my own in JS, for example, or begrudgingly use or wrap the python.datetime one (And not touch the third party python ones which do awful things inspired by Moment.js like conflating dates , times, and datetimes, under the guise dates and times don't have use on their own), but Chrono actually is comparatively nice (S-tier relative to others), both std and no_std.

  • poulpy123 5 hours ago

    I would have expected a modern language to have an extensive datetime library in its standard library

    • Sharlin an hour ago

      Jiff demonstrates the exact reason Rust doesn't ship a datetime library - at least not yet. It is extremely well understood that datetimes are one of the hardest abstractions to get right, and it took many years and several third-party attempts to get to this point. It would've been an extremely severe mistake to include datetime in std and then be forced to maintain a likely flawed API for all eternity. Luckily Rust devs knew and know better.

    • lambda 4 hours ago

      The problem with this model is that then you try to build all of the libraries that you anticipate users are going to need in one big go before you release version 1 of you language. Because you're trying to do a lot at once, they don't ask get the proper attention they deserve. Then, because of stability guarantees, you're stuck only making backwards compatible changes in the future (or you risk either constant breaking changes, or big changes where a lot changes at once forking the ecosystem, like Python 2 to 3). So if you made any mistakes in the library, you're stuck with them, only being about to deprecate but never really remove them.

      The alternative is to keep a relatively small standard library, and a good package manager, to make it easier for people to iterate on API design in third party packages. Major version changes in a single library can have much less impact accross the ecosystem than standard library packages. Eventually you may get a de facto standard, and sometimes they are then later incorporated into the standard library.

      This model isn't without its downsides; it can sometimes mean fragmentation when standardization would help, sometimes these de facto standard libraries can become important enough that they run into the same ecosystem fragmentation issues on major releases. But it allows for more flexibility.

      The latter model is what the Rust project decided on for everything outside of the most fundamental time types. Dates and times and timezones are notoriously hard to model in code, and easy to create API designs that are full of footguns, so this is a place where that extra freedom to iterate was more important than standardizing on an API early on.

      That iteration has led to a number of different libraries, including time, chrono, and now jiff, allowing for exploring the space of API design to really get it right rather than being stuck with what was available early on.

    • dminik 4 hours ago

      Any modern language recognizes that some things are inherently complex and will always have tradeoffs that certain users won't be satisfied with and that will be locked in forever. Such modern languages then let users pick whatever approach they actually need by implementing sensible package management.

      • darksaints 4 hours ago

        A default standard encompassing the most common usecases is a completely reasonable approach. Having a date/time library in the standard library does not preclude other libraries, it just makes it the default and keeps ecosystem integration sane. Not to mention the massive potential reduction in supply chain attacks.

        • kbolino 3 hours ago

          In this particular matter, I can't help but be biased against your perspective due to Go. In that language, the desire to meet the "most common usescases" has led to an IMO pathologically bad attitude towards doing this right. In Rust, only the bare primitives are exposed -- Instant, SystemTime, Duration -- but these at least allow for others to build better abstractions. Whereas, in Go, all of the primitives are kept hidden behind a "good enough" (it's not) abstract API, and you have to break out O/S-specific and/or unstable code if you want to do things better, especially where monotonic time is concerned.

          • darksaints 3 hours ago

            Java had the same problem, but then they then fixed with `java.time`, which I believe should be the benchmark for off-the-shelf date/time functionality. Doing it right absolutely is a management and leadership problem, and management/leadership can fail, but when it is done right the result is so much better than the bazaar of 20 half-baked mutually incompatible solutions.

            • kbolino 3 hours ago

              I don't agree that Java had the same problem. Java has had System.currentTimeMillis() since the beginning, and System.nanoTime() since 2005. Meanwhile, in Go, time.Now().Unix() performs a pointless timezone lookup and time.Since(foo) only uses the monotonic clock if foo has monotonic time, which is a hidden property of time.Time values that you can't interrogate.

              Of course, Go can always backtrack and expose the primitives, and Rust can always add a higher-level API, but as user of the languages, I'd rather have the latter problem than the former. It doesn't help that Go's zoned-time API isn't very good either.

            • stouset 2 hours ago

              The gold standard these days is JavaScript’s Temporal, which Jiff and java.time.temporal are descendants of.

        • masklinn 3 hours ago

          Having a date/time library in the standard library actually makes it very difficult for other libraries to take off, and when it's deeply deficient (which is generally the case, turns out time is quite hard) it's actively detrimental to users of the ecosystem, both because it's hell to use and because it teaches them to do things incorrectly. Which then makes an innovative library have a harder time take off, because they need to fix most of their possible users.

    • sunshowers 4 hours ago

      A poorly designed one, maybe. My understanding is that the Temporal model is a very recent invention.

      • masklinn 4 hours ago

        In fairness, Temporal largely follows the model originally defined by Joda, and refined in java.time. So I'd say that Java is probably one of the few languages with a well designed datetime library in the standard library.

        Temporal does improve some things (it has more strict zoning / less defaults, and improves serialization through RFC 9557), but some of the divergences are not necessarily improvements and rather divergences of opinion (e.g. java.time wilfully made non-ISO calendars second-class, Temporal makes them first class more like Joda, and it's one of the things Colebourne — the lead author of Joda and java.time — strongly disagrees with[1], but the Temporal authors have pretty compelling reasons for it[2]).

        [1] https://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941... https://github.com/tc39/proposal-temporal/issues/5 https://github.com/tc39/proposal-temporal/issues/1454

        [2] https://tc39.es/proposal-temporal/docs/calendar-review#why-a...

        • Sharlin an hour ago

          And Java needed two very flawed attempts before finally getting it more-or-less right (and as you said, it was a third-party library in the end that was adopted rather than one designed by the core developers.)

        • vips7L 4 hours ago

          I really enjoy working with java.time. It's one of the best additions to the standard library.

          • procaryote 2 hours ago

            Java has a pretty good approach of promoting the more popular library for a thing to standard library status, with relatively minor changes. It's an easy way to get a really good standard library over time, as it's already proven in practice

    • tredre3 4 hours ago

      Rust doesn't even have an async runtime in its standard library, despite async being part of the language. They believe increased reliance on third party dependencies is better for the ecosystem. Things like supply chain risks or disparate documentation or conflicting dependencies or enormous .cargo are seen as less of a problem than having a built-in API that could go stale one day.

      • JoshTriplett 2 hours ago

        > They believe increased reliance on third party dependencies is better for the ecosystem.

        Not at all. We just want to avoid having the standard library be "where code goes to die", as Python folks have put it.

        We're working on adding more popular APIs from the ecosystem to the standard library. See https://github.com/rust-lang/std-replacement-data/ for a data set tracking what crates have been obsoleted by additions to the standard library; we hope to increase that over time.

      • hmry 3 hours ago

        I don't know about some of those points (maybe you could expand on them)

        > disparate documentation

        I've never experienced this while using a Rust library. They all use rustdoc hosted on docs.rs (or locally with $ cargo doc). They all look identical and there's a single global search bar that searches all your dependencies.

        > conflicting dependencies

        Since you can install two different versions of the same library, this is only an issue if two of your dependencies both expose a transitive dependency with different versions in their external APIs. (E.g. libA returns a Foo 1.0 and libB expects an argument of Foo 2.0) Only library I've ever run into this with is raw-window-handle.

        > supply chain risks

        > enormous .cargo

        These I agree with. Although honestly the supply chain risk is not as big with these foundational libraries as it would first appear, since they are almost all maintained by the same 5 rust compiler developers. Really the only difference is that they're not in the rust-lang github organization and not shipped precompiled with the standard library

      • afdbcreid 4 hours ago

        As I've said in other places, supply chain risks have nothing to do with things not being in std, only with them not being official - and things can be (and are) official without being included in std.

        Documentation certainly has nothing to do with it.

        Other factors you mentioned are more convincing.

    • solidsnack9000 4 hours ago

      I'm not sure this makes sense for a systems programming language -- but I can see it for an application programming language.

      For a systems programming language, Rust is relatively easy to write applications in -- but I suspect standard library choices (and other choices) will be driven by the systems side for the foreseeable future.

  • pbrowne011 4 hours ago

    Nice! I appreciated the documentation for tzdb on avoiding embedding and the thought process behind using "rearguard" data [1]. Some related GitHub issues are also worth reading [2] [3].

    [1] https://docs.rs/jiff-tzdb/latest/jiff_tzdb/#data-generation

    [2] https://github.com/BurntSushi/jiff/issues/278

    [3] https://github.com/BurntSushi/jiff/issues/279

    • barchar 3 hours ago

      I do wish they could use the system database on windows. Windows does maintain this data, but it's not in the same format.

      The C++ date-time library goes and loads the system copy of ICU (which is updated via windows update) and pulls the tz data from ICU's calendar api.

  • robrain 4 hours ago
  • fstephany 5 hours ago

    Jiff will probably be the default datetime library for a lot of Rustaceans (and LLMs) in the years to come.

    Thank you for your work on this burntsushi!

  • kjuulh 4 hours ago

    Jiff is very nice to work with. It is always a pleasure working with something crafted by burntsushi

  • arjie 3 minutes ago

    My favourite part about BurntSushi software was that the structure of the program was enough that even a novice at the language could change things. Very well laid out. I had a fork of many of his applications for personal use and it was always trivial to jump in and edit. Excellent stuff.

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

    This is classic anti-trust monopoly leveraging. Lucky I'm on this side of the debate :)

  • Sparkle-san 5 hours ago

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

    Woah now, let's not get too controversial.

    • dmit 5 hours ago

      The man's name is "burnt sushi". I suspect he's fine with controversy. :)

    • flufluflufluffy 4 hours ago

      if I ever use this lib i'm gonna be scowling with this in the back of my mind the whole time xD

      Graphics Interchange Format. Guh-raphics. GIF

      • berkes 5 minutes ago

        Graphics. Like that long-necked animal?

    • MadameMinty 4 hours ago

      Out of pure spite, I will pronounce Jiff like "gif", with a hard "g", as in "good".

  • gosen 4 hours ago

    I thought it's the right moment to finally do something with Rust, but I work on my "J" pronunciation first

  • brianwitte 5 hours ago

    the jiff pronunciation meta got my brain working hard for second. love it

    • the__alchemist 4 hours ago

      With how my brain pronounces short names and acronyms etc vs the commonly-accepted ones, this one has to be something like like "Geth".

      > Jiff is pronounced like “gif”

      This would have been a hilarious line if he left off the second part!

  • PowerElectronix 4 hours ago

    Weird, you can't ever pronounce Jiff as gif.

  • NetOpWibby 4 hours ago

    Love seeing the correct pronunciation of gif