Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Normalize FakeTimeProvider timestamps to UTC - #7980

Open
lqkhanh295 wants to merge 1 commit into
dotnet:mainfrom
lqkhanh295:fix/fake-time-provider-utc-offset
Open

lqkhanh295 wants to merge 1 commit into
dotnet:mainfrom
lqkhanh295:fix/fake-time-provider-utc-offset

Conversation

@lqkhanh295

@lqkhanh295 lqkhanh295 commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #7979

FakeTimeProvider stored the DateTimeOffset passed to its constructor, SetUtcNow, and AdjustTime directly in _now without converting to UTC. Passing a non-zero offset caused GetUtcNow() (and Start) to return a non-zero offset, violating the TimeProvider.GetUtcNow() contract.

Because timers (AddWaiter / WakeWaiters) and GetTimestamp() read _now.Ticks rather than _now.UtcTicks, keeping a non-zero offset in _now also skewed timer wake-ups and elapsed timestamps whenever offsets differed across SetUtcNow or AdjustTime calls.

Convert incoming DateTimeOffset values via .ToUniversalTime() in the constructor, SetUtcNow, and AdjustTime, and add tests covering positive and negative offsets for all three methods.

Microsoft Reviewers: Open in CodeFlow

Convert DateTimeOffset inputs via ToUniversalTime() in the constructor, SetUtcNow, and AdjustTime so GetUtcNow() always returns a zero offset and internal _now.Ticks timer/timestamp calculations stay in UTC.

Fixes dotnet#7979
@lqkhanh295
lqkhanh295 requested a review from a team as a code owner November 25, 2026 09:21
Copilot AI balanced review requested due to automatic review settings November 25, 2026 09:21

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

🟢 Approval recommended

No active review issues are reported for the FakeTimeProvider UTC-normalization change.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FakeTimeProvider keeps a non-UTC offset in GetUtcNow()

2 participants