humantime
humantime copied to clipboard
Support fractional durations
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).
In the general case, It's unclear what precision of that should be. Is it all the way to nanoseconds?
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?
For my use case, that would be unnecessary (seconds are enough). But it makes sense for
1.5 hourto be as precise as1 hour 30 minas 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.
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.
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.