Strip fractional seconds in ParseDockerTimestamp#40495
Open
benhillis wants to merge 2 commits into
Open
Conversation
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes parsing of Docker ISO 8601 timestamps that include fractional seconds by normalizing the input before std::chrono::parse, preventing valid timestamps (e.g. ...00.123456789Z) from throwing E_INVALIDARG.
Changes:
- Normalize Docker timestamps by stripping the optional fractional seconds portion before parsing.
- Keep existing
%Z-based parsing behavior while ensuring epoch-second precision remains correct.
Member
Author
|
I'm not totally sold on this one. |
Member
Author
Ok, I think I've convinced myself this is real and worth doing. |
The chrono parse format `%FT%H:%M:%S%Z` does not consume the optional fractional seconds component that Docker emits in ISO 8601 timestamps (e.g. `2026-03-05T10:30:00.123456789Z`). For timestamps with a fractional component the parse fails and `THROW_HR_IF_MSG` reports an `E_INVALIDARG` for what is in fact a valid Docker timestamp. Strip the fractional component (between `.` and the timezone marker `Z` / `+` / `-`) before parsing. The function returns epoch seconds, so the dropped sub-second precision is irrelevant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The '.' itself can't match 'Z', '+' or '-', so starting find_first_of one past dot makes the intent slightly clearer and avoids an unnecessary comparison. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3bf072e to
1a4c4b3
Compare
Comment on lines
+309
to
+313
| // We only need epoch seconds, so strip the optional fractional component before parsing. | ||
| std::string normalized = timestamp; | ||
| if (const auto tPos = normalized.find('T'); tPos != std::string::npos) | ||
| { | ||
| if (const auto dot = normalized.find('.', tPos + 1); dot != std::string::npos) |
OneBlue
reviewed
May 12, 2026
| // Docker timestamps are UTC ISO 8601, e.g. "2026-03-05T10:30:00.123456789Z". | ||
| // We only need epoch seconds, so strip the optional fractional component before parsing. | ||
| std::string normalized = timestamp; | ||
| if (const auto tPos = normalized.find('T'); tPos != std::string::npos) |
Collaborator
There was a problem hiding this comment.
Instead of doing this, I think we can just drop the %Z part of the format and std::chrono::parse() should just ignore the fractional second part
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.
Split out from #40489.
The chrono parse format
%FT%H:%M:%S%Zdoes not consume the optional fractional seconds component that Docker emits in ISO 8601 timestamps (e.g.2026-03-05T10:30:00.123456789Z). For timestamps with a fractional component the parse fails and the call throwsE_INVALIDARGfor what is actually a valid Docker timestamp.Change
src/windows/wslcsession/WSLCContainer.cpp: strip the optional fractional component (between.and the timezone markerZ/+/-) before parsing. The function returns epoch seconds, so dropping sub-second precision is correct.Validation
%Zparse forZ/ abbreviated zones still runs unchanged.2026-03-05T10:30:00Z— no., unchanged2026-03-05T10:30:00.123456789Z— fractional stripped beforeZ2026-03-05T10:30:00.123+05:00— fractional stripped before+