fix: correct fractional seconds normalization in RFC3339 parser - #242
Merged
vlastahajek merged 1 commit intoJun 9, 2026
Merged
Conversation
In convertRfc3339(), the intent was to normalize a sub-6-digit fractional seconds value to microseconds by multiplying by a power of 10. The code used the ^ operator for this, which in C++ is bitwise XOR - not exponentiation. There is no exponentiation operator in C++. This caused incorrect microsecond values for any RFC3339 timestamp with fewer than 6 fractional digits. The most common real-world case is 3-digit millisecond precision (e.g. '2020-02-18T10:34:08.135Z'), where the multiplier becomes 10 XOR 3 = 9 instead of 1000, producing a result roughly 111x too small. Timestamps with 6 digits (microseconds) or 7-9 digits (nanoseconds, truncated to 6 before this branch) are not affected. The struct tm fields (year, month, day, hour, minute, second) are parsed separately by sscanf and are always correct. Only the sub-second microseconds field is affected. Fix: replace the single XOR expression with an explicit multiply loop, which avoids pulling in <math.h> for pow() and keeps the arithmetic integer throughout.
Contributor
Author
|
Have you seen this PR @tobiasschuerg ? |
vlastahajek
approved these changes
Jun 9, 2026
vlastahajek
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for noticing this and for the PR!.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In convertRfc3339(), the intent was to normalize a sub-6-digit fractional seconds value to microseconds by multiplying by a power of 10. The code used the ^ operator for this, which in C++ is bitwise XOR - not exponentiation. There is no exponentiation operator in C++.
This caused incorrect microsecond values for any RFC3339 timestamp with fewer than 6 fractional digits. The most common real-world case is 3-digit millisecond precision (e.g. '2020-02-18T10:34:08.135Z'), where the multiplier becomes 10 XOR 3 = 9 instead of 1000, producing a result roughly 111x too small.
Timestamps with 6 digits (microseconds) or 7-9 digits (nanoseconds, truncated to 6 before this branch) are not affected.
The struct tm fields (year, month, day, hour, minute, second) are parsed separately by sscanf and are always correct. Only the sub-second microseconds field is affected.
Proposed Changes
replace the single XOR expression with an explicit multiply loop, which avoids pulling in <math.h> for pow() and keeps the arithmetic integer throughout.
Checklist