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

Panicked at duration_round by zero #658

Closed
ARBaart opened this issue Mar 21, 2022 · 2 comments
Closed

Panicked at duration_round by zero #658

ARBaart opened this issue Mar 21, 2022 · 2 comments

Comments

@ARBaart
Copy link
Contributor

ARBaart commented Mar 21, 2022

Hi, I ran into the following panic error in my Rust project using the duration_round method of chrono. The error is

panicked at 'attempt to calculate the remainder with a divisor of zero', /root/.cargo/registry/src/github.com-(...)/chrono-0.4.19/src/round.rs:161:30"

In the current master I think this corresponds to the following line:

let delta_down = stamp % span;

It seems like duration_round doesn't check if the amount it is rounded by is zero, because the remainder operation (%) panics when used with zero as rhs. While rounding by zero doesn't make a lot of sense, the expected behaviour in the limit from higher values should probably be to just return the original value, unrounded.

Using Rust 1.56.0 and chrono 0.4.19

ARBaart pushed a commit to ARBaart/chrono that referenced this issue Mar 21, 2022
ARBaart pushed a commit to ARBaart/chrono that referenced this issue Mar 21, 2022
@djc
Copy link
Contributor

djc commented Mar 21, 2022

Would you be able to submit a PR? I notice you're already working on a fix.

@ARBaart
Copy link
Contributor Author

ARBaart commented Mar 21, 2022

Would you be able to submit a PR? I notice you're already working on a fix.

Yes, see #659

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

2 participants