Remix.run Logo
▲ Jiff 1.0: A datetime library for Rust(burntsushi.net)
121 points by burntsushi 2 hours ago | 31 comments
▲ddahlen 41 minutes ago | parent | next [-]

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 38 minutes ago | parent [-]

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 29 minutes ago | parent [-]

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.

▲mgrandl an hour ago | parent | prev | next [-]

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 an hour ago | parent [-]

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

▲the__alchemist an hour ago | parent | prev | next [-]

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.

▲masklinn 35 minutes ago | parent | next [-]

> I will roll my own in JS

Hopefully Safari will soon have temporal implemented and we can leave that behind (it's in 27.3b so not out of the question).

> Chrono actually is comparatively nice

burntsushi has written pretty extensively about:

1. comparisons to existing datetime libraries (https://docs.rs/jiff/latest/jiff/_documentation/comparison/i...), chrono's original author also commented (https://github.com/BurntSushi/jiff/issues/63)

2. why they felt it was a good idea to write a new library (https://docs.rs/jiff/latest/jiff/_documentation/design/index...)

3. why they didn't wish to contribute to either chrono or time (https://docs.rs/jiff/latest/jiff/_documentation/design/index...)

And as randomblock linked, chrono is deprecating itself.

▲the__alchemist 11 minutes ago | parent [-]

Ty for the details! That is about as clear as anyone could hope!

This is still very surprising given the context; if the top datetime library of any language is getting soft-replaced with something nicer, woe be to those in other languages!

▲randomblock1 41 minutes ago | parent | prev [-]

Chrono is deprecated: https://github.com/chronotope/chrono/issues/1768

I found switching to Jiff from Chrono quite easy.

▲kjuulh 16 minutes ago | parent | prev | next [-]

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

▲poulpy123 an hour ago | parent | prev | next [-]

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

▲lambda 25 minutes ago | parent | next [-]

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 an hour ago | parent | prev | next [-]

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 17 minutes ago | parent [-]

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.

▲solidsnack9000 an hour ago | parent | prev | next [-]

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.

▲tredre3 an hour ago | parent | prev | next [-]

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.

▲afdbcreid 19 minutes ago | parent [-]

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.

▲sunshowers an hour ago | parent | prev [-]

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

▲masklinn 27 minutes ago | parent [-]

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...

▲vips7L 19 minutes ago | parent [-]

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

▲pbrowne011 38 minutes ago | parent | prev | next [-]

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

▲robrain 26 minutes ago | parent | prev | next [-]

Previously on HN (pre-1.0): https://news.ycombinator.com/item?id=41031037

▲fstephany an hour ago | parent | prev | next [-]

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!

▲Sparkle-san an hour ago | parent | prev | next [-]

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

Woah now, let's not get too controversial.

▲MadameMinty 6 minutes ago | parent | next [-]

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

▲flufluflufluffy 5 minutes ago | parent | prev | next [-]

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

▲dmit an hour ago | parent | prev [-]

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

▲gosen 39 minutes ago | parent | prev | next [-]

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

▲PowerElectronix 34 minutes ago | parent | prev | next [-]

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

▲brianwitte an hour ago | parent | prev | next [-]

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

▲NetOpWibby an hour ago | parent | prev [-]

Love seeing the correct pronunciation of gif