Live data from Hacker News

Jiff: Datetime library for Rust

github.com

31–40 of 249 posts

Re: Jiff: Datetime library for Rust

#31

Overall this looks nice, but I found myself stumbling over the ToSpan syntax: let span = 5.days().hours(8).minutes(1); It feels sort of weird how the first number appears in front, and then all the other ones are function arguments. I suppose if you don't like that you can just write: let span = Span::new().days(5).hours(8).minutes(1); at the expense of a couple characters, which is not too bad.

I stumbled over use jiff::{Timestamp, ToSpan}; fn main() -> Result { let time: Timestamp = "2024-07-11T01:14:00Z".parse()?; I seem to remember Rust does that thing with interfaces instead of classes, is it that? How come I import a library and all of a sudden strings have a `parse()` method that despite its generic name results in a `Timestamp` object? or is it the left-hand side that determines which meaning `str.pa…

All of these options work and are equivalent.

- let time = Timestamp::parse("2024-07-11T01:14:00Z")?;

- let time: Timestamp = "2024-07-11T01:14:00Z".parse()?;

- let time = "2024-07-11T01:14:00Z".parse::()?;

You’re free to choose whatever you prefer, although the compiler needs to be able to infer the type of time. If it can’t, it’ll let you know.

So a fourth option is allowed, as long as the subsequent lines make the type of time unambiguous.

- let time = "2024-07-11T01:14:00Z".parse()?;

This is a direct consequence of Timestamp implementing the FromStr trait.

Re: Jiff: Datetime library for Rust

#33
post #32
post #2

Not to mention that BurntSushi is the author of the entire rust regex ecosystem

I remember getting into a debate with him on Reddit about something or other and then realizing who I was debating with and saying never mind.

That shouldn't stop you from settling an argument (given it was respectful). The best way to learn is to be wronged by smarter people.

Re: Jiff: Datetime library for Rust

#34
post #4

Earlier quoted context omitted.

If only Rust had named function parameters, you could write what is IMHO the most readable option: Span::new(days=5, hours=8, minutes=1)

could you do that with `struct` / `record` fields? In JavaScript which doesn't have named function parameters either I often write functions with a single `cfg` parameter that are called like `f({ hours: 2, seconds: 53, })` which I find nice b/c it re-uses existing data structures.

Kind of inefficient. Also it's less ergonomic since every struct is it's own type, so you need to have the signature on both sides.

Re: Jiff: Datetime library for Rust

#36

Earlier quoted context omitted.

I've seen it being used in ECMAScript's Temporal https://tc39.es/proposal-temporal/docs/strings.html

Ah, thank you. Now that I'm back at my desk I had to check ISO8601, that suffix is not included. However it does look like an extension - RFC 9557 - which looks like is still in proposed state. I would personally caution using these suffixes until wider adoption, because AFAIK the Olson database names themselves are not standardised on non-POSIX systems (i.e you might have a hard time on Windows).

The database names are standardized: https://www.iana.org/time-zones

The database itself may not be available but there are various implementations including Windows https://data.iana.org/time-zones/tz-link.html#software

Re: Jiff: Datetime library for Rust

#37
post #4

Overall this looks nice, but I found myself stumbling over the ToSpan syntax: let span = 5.days().hours(8).minutes(1); It feels sort of weird how the first number appears in front, and then all the other ones are function arguments. I suppose if you don't like that you can just write: let span = Span::new().days(5).hours(8).minutes(1); at the expense of a couple characters, which is not too bad.

If only Rust had named function parameters, you could write what is IMHO the most readable option: Span::new(days=5, hours=8, minutes=1)

Yes, that could've been lended almost as-is from OCaml, in particular as Rust doesn't have partial application so optional arguments would work out-of-the-box as well.

Re: Jiff: Datetime library for Rust

#38
post #8

Overall this looks nice, but I found myself stumbling over the ToSpan syntax: let span = 5.days().hours(8).minutes(1); It feels sort of weird how the first number appears in front, and then all the other ones are function arguments. I suppose if you don't like that you can just write: let span = Span::new().days(5).hours(8).minutes(1); at the expense of a couple characters, which is not too bad.

I agree. Personally, I'd prefer let span = 5.days() + 8.hours() + 1.minutes();

Have you checked the API to see if that works? I imagine it does.

Re: Jiff: Datetime library for Rust

#39
post #8

Overall this looks nice, but I found myself stumbling over the ToSpan syntax: let span = 5.days().hours(8).minutes(1); It feels sort of weird how the first number appears in front, and then all the other ones are function arguments. I suppose if you don't like that you can just write: let span = Span::new().days(5).hours(8).minutes(1); at the expense of a couple characters, which is not too bad.

I agree. Personally, I'd prefer let span = 5.days() + 8.hours() + 1.minutes();

Looks like it should be supported: https://docs.rs/jiff/latest/jiff/struct.Span.html#impl-Add%3...

Re: Jiff: Datetime library for Rust

#40
This looks like a cool library.

Does anyone know why burntsushi is making this new library? I haven't messed around with times in rust much, but do the existing libraries have performance problems? Or are the existing API's awkward to use? Or is he just doing it for fun, or some other reason?

Post reply on HN