Skip to content

Strip fractional seconds in ParseDockerTimestamp#40495

Open
benhillis wants to merge 2 commits into
microsoft:masterfrom
benhillis:user/benhill/fix-docker-timestamp-fractional
Open

Strip fractional seconds in ParseDockerTimestamp#40495
benhillis wants to merge 2 commits into
microsoft:masterfrom
benhillis:user/benhill/fix-docker-timestamp-fractional

Conversation

@benhillis
Copy link
Copy Markdown
Member

Split out from #40489.

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 the call throws E_INVALIDARG for what is actually a valid Docker timestamp.

Change

  • src/windows/wslcsession/WSLCContainer.cpp: strip the optional fractional component (between . and the timezone marker Z / + / -) before parsing. The function returns epoch seconds, so dropping sub-second precision is correct.

Validation

  • Mechanical normalization; %Z parse for Z / abbreviated zones still runs unchanged.
  • Manual review of representative inputs:
    • 2026-03-05T10:30:00Z — no ., unchanged
    • 2026-03-05T10:30:00.123456789Z — fractional stripped before Z
    • 2026-03-05T10:30:00.123+05:00 — fractional stripped before +

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
@benhillis
Copy link
Copy Markdown
Member Author

I'm not totally sold on this one.

@benhillis
Copy link
Copy Markdown
Member Author

I'm not totally sold on this one.

Ok, I think I've convinced myself this is real and worth doing.

benhillis and others added 2 commits May 12, 2026 14:53
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>
@benhillis benhillis marked this pull request as ready for review May 12, 2026 21:53
@benhillis benhillis requested a review from a team as a code owner May 12, 2026 21:53
Copilot AI review requested due to automatic review settings May 12, 2026 21:53
@benhillis benhillis force-pushed the user/benhill/fix-docker-timestamp-fractional branch from 3bf072e to 1a4c4b3 Compare May 12, 2026 21:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

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)
// 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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Successfully merging this pull request may close these issues.

3 participants