Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support fractional durations #34

Open
schneiderfelipe opened this issue Dec 18, 2022 · 5 comments
Open

Support fractional durations #34

schneiderfelipe opened this issue Dec 18, 2022 · 5 comments

Comments

@schneiderfelipe
Copy link

schneiderfelipe commented Dec 18, 2022

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

@tailhook
Copy link
Owner

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

@schneiderfelipe
Copy link
Author

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?

@tailhook
Copy link
Owner

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.

@schneiderfelipe
Copy link
Author

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.

@9999years
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants