Live data from Hacker News

Jiff: Datetime library for Rust

github.com

61–70 of 249 posts

Re: Jiff: Datetime library for Rust

#61
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)

I'm all for named parameters. C++ is sorely lacking that feature as well.

Currently using vs code with C++, I like how it handles the missing language feature by adding a grayed out parameter name before the value for function calls and initializers. Maybe there is something like that for rust.

Re: Jiff: Datetime library for Rust

#62

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.

Can you do 5.days() + 8.hours() + 1.minutes()?

Re: Jiff: Datetime library for Rust

#63
post #53

Earlier quoted context omitted.

Not at all. If this library was GPL, any software using it also needs to be GPL. This means all code needs to be open source, which severely limits freedom of makers of end-user software. And almost the whole Rust ecosystem is MIT.

> severely limits freedom of makers of end-user software Ironic for a "free" software license. It would be great if there was a license somewhere inbetween GPL and MIT: you'd be required to upstream (or make available) any changes you made to the parts of other people's code you're making use of, but not required to open your entire codebase.

I think the MPL attempts to be that license.

Re: Jiff: Datetime library for Rust

#64
post #56
post #42

Earlier quoted context omitted.

Yeah, or there could simply be a `days()` free function (and equivalents of the other methods too). No need for struct constructors to be associated functions.

I haven't tried it (so I'm sorry if it's wrong or not what you're talking about) but can't you get a freestanding days function by use jiff::ToSpan::days;

You cannot import trait methods as free standing functions. I'm not sure if there was a discussion about making this a possibility but it's definitely not something you can do today.

Re: Jiff: Datetime library for Rust

#65
post #44
post #31

Earlier quoted context omitted.

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 th…

let time = Timestamp::from_str("2024-07-11T01:14:00Z")?; I think you meant :)

Haha, yes I did. If only the HN textbox integrated with rust-analyzer, it would have caught the mistake.

Re: Jiff: Datetime library for Rust

#66
post #54
post #37

Earlier quoted context omitted.

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.

Are named arguments on the roadmap somewhere? Or is it a won't-fix?

I haven't seen anything for or against in actual roadmaps. But there is, of course, at least one pre-proposal:

https://internals.rust-lang.org/t/pre-rfc-named-arguments/16...

It doesn't think about optional arguments (but somehow does include overloading). And a bit in a related fashion, it doesn't permit for reordering calling arguments, which I consider a downside:

> Reordering named arguments when calling

> No it is not possible. Just like unnamed arguments and generics, named arguments are also position-based and cannot be reordered when calling: register(name:surname:) cannot be called as register(surname:name:).

> Reordering them at the definition site is an API break, just like reordering unnamed arguments or generics is an API break already.

The rationale for this expressed in the comments says it's incompatible with overloading, but to me I don't see why named arguments and overloading should go hand-in-hand—or, indeed, how desirable overloading is in the first place. Or why should overloading be able to overload that kind of scenario. The other reasons for this don't seem really problems at all.

    > fn func2(pub name: u32, name hidden: u32) { /\* ... */ }
    > fn func3(name hidden1: u32, name hidden2: u32) { /* ... */ }
> func2 and func3 could work in theory: named arguments as proposed in this RFC are position-based and their internal names are different: just like two arguments can have the same type without ambiguity, those functions could be allowed.

Maybe there are technical reasons that are simpler when considering type compatibility between function types that have or don't have labeled arguments? Seems the proposal has misunderstood something about OCaml labeled arguments when placing it under https://internals.rust-lang.org/t/pre-rfc-named-arguments/16... , though.

In addition the proposal doesn't seem to have a neat syntax for forwarding named parameters, like in constructing records you can just fill in a field called foo by mentioning its name by itself—or, like in OCaml you can have

    let foo ~bar = bar + 1
    let baz ~bar = foo ~bar

    let main () = baz ~bar:42
If it used the .-prefix as mentioned as an idea elsewhere, then this too could be naturally expressed.

Maybe there are other ideas how to go about the labeled arguments, though that one seems pretty well thought-out.

One thing I've enjoyed with Python (and Mypy) is the ability to require the caller to use named arguments with the asterisk marker in the parameter list. This idea is mentioned in the proposal.

Re: Jiff: Datetime library for Rust

#67
post #54
post #37

Earlier quoted context omitted.

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.

Are named arguments on the roadmap somewhere? Or is it a won't-fix?

The feature is controversial enough that it's basically a wontfix.

Re: Jiff: Datetime library for Rust

#68
post #54

Earlier quoted context omitted.

Are named arguments on the roadmap somewhere? Or is it a won't-fix?

The feature is controversial enough that it's basically a wontfix.

Is it really, though? I didn't read all the comments, but the ones I read, very few were opposing the concept as such: https://internals.rust-lang.org/t/pre-rfc-named-arguments/16...

However, many were opposing overloading the same pre-rfc was suggesting.

Re: Jiff: Datetime library for Rust

#69
post #53

Earlier quoted context omitted.

That's what I gather from Unlicense too (in fact, this is confirmed in a linked bug thread where the author says he "hates copyright"). I think the author is actually looking for the GPL but doesn't realise it yet. Unlicense can't make something free forever, no matter how hard the author wishes it. GPL can. In other words, Unlicense/MIT is idealistic, GPL is pragmatic. You can't turn off copyright, but you can make…

Not at all. If this library was GPL, any software using it also needs to be GPL. This means all code needs to be open source, which severely limits freedom of makers of end-user software. And almost the whole Rust ecosystem is MIT.

> which severely limits freedom of makers of end-user software

And thereby severely guarantees the freedom of said end-users.

The freedom to deny the freedom of another person is not a freedom worth discussing.

The author expressly dislikes copyright. GPL is still the only real cure to copyright. "Permissive" licences are corporate friendly. They allow corporations to take what they want and give back nothing. In this day and age it's more important than ever to empower individuals and limit the growth of corporations/oligopolies.

Re: Jiff: Datetime library for Rust

#70
post #55
post #49

The fact that we need a such complicated datetime library just means so many unncessary artificial complexities were introduced before (yes the daylight saving, leap seconds etc.)

> unncessary artificial complexities The very fact they are there, still used, and so on, contradicts "unnessary [sic]". Sure, it might be outdated now, or technically better alternatives might be there. But, in the end, software that deals with "The Real World" is going to be a complex, illogical mess. Because the real world is a complex, illogical mess. We could make a time that is global, counts resonant frequency…

And we're going to say "let's do this a day from now", leaving the software to decide whether that's 24, 23 or 25 hours from now. It could be any of those things, depending on where it was said and the DST changes for that timezone.

Or conversely, is a specified instant considered "tomorrow"?

Post reply on HN