Skip to content

fix: interpret Local-kind mock time against configured zone#1055

Merged
vbreuss merged 1 commit into
mainfrom
fix/local-kind-timezone-bug
Jul 11, 2026
Merged

fix: interpret Local-kind mock time against configured zone#1055
vbreuss merged 1 commit into
mainfrom
fix/local-kind-timezone-bug

Conversation

@vbreuss

@vbreuss vbreuss commented Jul 11, 2026

Copy link
Copy Markdown
Member

The mock time system stored a Local-kind input instant as-is in the constructor and normalized it via ToUniversalTime() in SetTo. Both interpret a Local instant against the host machine's time zone, so DateTime.Now/UtcNow and DateTimeOffset.Now/UtcNow depended on the host zone when a custom LocalTimeZone differed from it - defeating the library's determinism guarantee.

Normalize Local-kind input to UTC using the mock's configured _localTimeZone in both the constructor and SetTo, so _now is always UTC and every consumer is corrected at the boundary. Unspecified is still treated as UTC and already-Utc values are untouched.

Update the Use(...) XML-doc remarks to state how Local-kind input is interpreted, and add regression tests asserting the result depends only on the configured zone, not the host.


@vbreuss vbreuss self-assigned this Jul 11, 2026
@vbreuss vbreuss added the bug Something isn't working label Jul 11, 2026
The mock time system stored a `Local`-kind input instant as-is in the
constructor and normalized it via `ToUniversalTime()` in `SetTo`. Both
interpret a `Local` instant against the *host machine's* time zone, so
`DateTime.Now`/`UtcNow` and `DateTimeOffset.Now`/`UtcNow` depended on the
host zone when a custom `LocalTimeZone` differed from it - defeating the
library's determinism guarantee.

Normalize `Local`-kind input to UTC using the mock's configured
`_localTimeZone` in both the constructor and `SetTo`, so `_now` is always
UTC and every consumer is corrected at the boundary. `Unspecified` is still
treated as UTC and already-`Utc` values are untouched.

Update the `Use(...)` XML-doc remarks to state how `Local`-kind input is
interpreted, and add regression tests asserting the result depends only on
the configured zone, not the host.
@vbreuss vbreuss force-pushed the fix/local-kind-timezone-bug branch from c8e0d7e to d69a5e3 Compare July 11, 2026 10:11
@sonarqubecloud

Copy link
Copy Markdown

@vbreuss vbreuss enabled auto-merge (squash) July 11, 2026 10:54
@vbreuss vbreuss merged commit e164caf into main Jul 11, 2026
13 checks passed
@vbreuss vbreuss deleted the fix/local-kind-timezone-bug branch July 11, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DateTimeOffset support to ITimeSystem

1 participant