humantime icon indicating copy to clipboard operation
humantime copied to clipboard

Support fractional durations

Open schneiderfelipe opened this issue 2 years ago • 5 comments

It would be nice to have 1.5 hour parsed the same way 1 hour 30 min is.

EDIT: the error is currently duration::Error::InvalidCharacter(1).

schneiderfelipe avatar Dec 18 '22 13:12 schneiderfelipe

In the general case, It's unclear what precision of that should be. Is it all the way to nanoseconds?

tailhook avatar Dec 19 '22 13:12 tailhook

For my use case, that would be unnecessary (seconds are enough). But it makes sense for 1.5 hour to be as precise as 1 hour 30 min as possible?

schneiderfelipe avatar Dec 20 '22 15:12 schneiderfelipe

For my use case, that would be unnecessary (seconds are enough). But it makes sense for 1.5 hour to be as precise as 1 hour 30 min as possible?

Well, but this should be configurable then, and it's a big piece of code in this case.

We probably have to do Duration::from_secs_f64(3600.*float_hours) instead. But then I'm not sure if just decimals are enough or somebody also wants exponential notation.

So I'm not sure if I want to open this can of worms.

tailhook avatar Dec 21 '22 12:12 tailhook

We probably have to do Duration::from_secs_f64(3600.*float_hours) instead. But then I'm not sure if just decimals are enough or somebody also wants exponential notation.

Exponential notation would be too much, I think. Just parsing a simple float (\d+\.\d+) and doing the multiplication you suggested would be more than enough for most use cases I think.

schneiderfelipe avatar Dec 21 '22 13:12 schneiderfelipe

Agreed that support for float durations would be really nice (I want to be able to parse 0.5 seconds).

I do understand not wanting to open this can of worms -- floats are tricky and this could add a lot of complexity. At the same time, I think @schneiderfelipe is right that even the most naive implementation would be very useful.

If this feature isn't added, we should improve the error message to clarify that decimals aren't allowed.

9999years avatar Jun 15 '23 16:06 9999years