Skip to content

Handle XmlConvert unspecified DateTimeOffset at local time-zone boundaries - #130815

Merged
mconnew merged 5 commits into
mainfrom
copilot/fix-argumentoutofrangeexception
Jul 16, 2026
Merged

mconnew merged 5 commits into
mainfrom
copilot/fix-argumentoutofrangeexception

Conversation

Copilot AI commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #130814

XmlConvert.ToDateTimeOffset could throw for unspecified local times at the DateTime boundaries when applying the local UTC offset would push the value outside DateTimeOffset's representable UTC range. This updates the XML conversion path to clamp only the boundary cases that cannot be represented, while preserving existing behavior for representable offsets.

  • Conversion fix

    • Update System.Xml.Schema.XsdDateTime's implicit DateTimeOffset conversion for XsdDateTimeKind.Unspecified.
    • Return DateTimeOffset.MinValue only when DateTime.MinValue with a non-negative local offset would underflow.
    • Return DateTimeOffset.MaxValue only when DateTime.MaxValue with a non-positive local offset would overflow.
    • Keep existing offset-preserving behavior for representable boundary values.
  • Regression coverage

    • Add RemoteExecutor-based Unix tests that change TZ and validate both sides of the boundary behavior.
    • Cover:
      • 0001-01-01T00:00:00 in positive-offset and negative-offset local time zones
      • 9999-12-31T23:59:59.9999999 in positive-offset and negative-offset local time zones
  • Test infrastructure

    • Enable RemoteExecutor for System.Private.Xml tests so the time-zone-sensitive cases can run in isolated processes.
TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset(dt);

if (dt == DateTime.MinValue && offset >= TimeSpan.Zero)
{
    result = DateTimeOffset.MinValue;
}
else if (dt == DateTime.MaxValue && offset <= TimeSpan.Zero)
{
    result = DateTimeOffset.MaxValue;
}
else
{
    result = new DateTimeOffset(dt, offset);
}

Copilot AI self-assigned this Jul 15, 2026
Copilot AI review requested due to automatic review settings July 15, 2026 19:28
Copilot AI removed the request for review from Copilot July 15, 2026 19:28
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
15 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 20:07
Copilot AI changed the title [WIP] Fix ArgumentOutOfRangeException in XmlConvert.ToDateTimeOffset Handle XmlConvert unspecified DateTimeOffset at local time-zone boundaries Jul 15, 2026
Copilot AI requested a review from mconnew July 15, 2026 20:08
Copilot AI temporarily deployed to copilot-pat-pool July 15, 2026 20:15 Inactive
Copilot AI temporarily deployed to copilot-pat-pool July 15, 2026 20:16 Inactive
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.

@tarekgh tarekgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@tarekgh tarekgh added this to the 11.0.0 milestone Jul 15, 2026
@tarekgh
tarekgh marked this pull request as ready for review July 15, 2026 21:37
Copilot AI review requested due to automatic review settings July 15, 2026 21:37
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the System.Xml.Schema.XsdDateTime → DateTimeOffset conversion for Unspecified kinds to avoid exceptions at the DateTime min/max boundaries when the local UTC offset would push the UTC instant outside DateTimeOffset’s representable range. It also adds regression coverage that runs under isolated processes with a controlled time zone.

Changes:

  • Clamp DateTime.MinValue/DateTime.MaxValue conversions to DateTimeOffset.MinValue/DateTimeOffset.MaxValue only for the non-representable local-offset boundary cases.
  • Add Unix RemoteExecutor tests that vary TZ and validate boundary behavior for both positive and negative offsets.
  • Enable RemoteExecutor support in System.Private.Xml tests via IncludeRemoteExecutor.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs Adds boundary-only clamping logic for Unspecified → DateTimeOffset conversions.
src/libraries/System.Private.Xml/tests/XmlConvert/XmlConvertEndOfDayTests.cs Adds RemoteExecutor-based timezone-isolated regression tests for min/max boundary conversions.
src/libraries/System.Private.Xml/tests/System.Private.Xml.Tests.csproj Enables RemoteExecutor for the test project.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings July 15, 2026 21:46
@tarekgh
tarekgh temporarily deployed to copilot-pat-pool July 15, 2026 21:46 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated 2 comments.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings July 15, 2026 21:53
@mconnew
mconnew temporarily deployed to copilot-pat-pool July 15, 2026 21:53 — with GitHub Actions Inactive
@mconnew
mconnew temporarily deployed to copilot-pat-pool July 15, 2026 21:53 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 22:24
Copilot AI requested a review from tarekgh July 15, 2026 22:25

@brianrob brianrob left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Copilot AI temporarily deployed to copilot-pat-pool July 15, 2026 22:36 Inactive
Copilot AI temporarily deployed to copilot-pat-pool July 15, 2026 22:36 Inactive
@mconnew
mconnew enabled auto-merge (squash) July 16, 2026 00:32
@mconnew
mconnew merged commit 1594ad1 into main Jul 16, 2026
90 checks passed
@mconnew
mconnew deleted the copilot/fix-argumentoutofrangeexception branch July 16, 2026 07:01
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — b23fdc51 Deployed Jul 15, 2026 by Copilot via pat_pool #15257
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Xml.XmlConvert.ToDateTimeOffset("0001-01-01T00:00:00") throws ArgumentOutOfRangeException for timezones with positive offset

5 participants