-
Notifications
You must be signed in to change notification settings - Fork 122
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
fix: handle parsing ISO datetimes where the microseconds round up to 1s or more #1084
fix: handle parsing ISO datetimes where the microseconds round up to 1s or more #1084
Conversation
Hmm, actually, this could overflow into minutes, then into hours, etc. Will fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, nice find! This bug has been lurking here since I wrote it. It will happen 500/1,000,000,000 times, or 1 in 2 million, so it's definitely not crazy that it happened.
Yeah, I do think we should truncate to converge on the new stdlib's behaviour. Does it truncate only when the nanoseconds are >= 999999500, or for all values?
Although with those odds I think you can legitimately feel unlucky if it happens to you 😂
Only then, basically. It's just slicing the original string and ignoring anything after the 6th digit. I checked the CPython code for |
Okay, in that case let's keep using |
Thanks for the report and the fix! |
We handle microseconds with more than 6 digits if the number of microseconds can be rounded to a number < 1M; for example:
However, if rounding takes us to the next second, we fail; for example:
Handle this case by putting an upper bound on the microseconds of 999,999 (truncating to that if the value would round to be higher).
Note that it looks like the Python 3.11+ standard library (which includes this functionality) truncates instead of rounds (at least in the Python
_pydatetime
- I haven't looked at the C implementation). Rounding seems more correct to me, but we should duplicate the stdlib behaviour since we'll presumably move to using that once we have Python 3.11 as a minimum Python version.Fixes #1083