Skip to content

fix: default MockTimeSystem to the local time zone#1062

Merged
vbreuss merged 1 commit into
mainfrom
feature/mocktimesystem-local-timezone-default
Jul 14, 2026
Merged

fix: default MockTimeSystem to the local time zone#1062
vbreuss merged 1 commit into
mainfrom
feature/mocktimesystem-local-timezone-default

Conversation

@vbreuss

@vbreuss vbreuss commented Jul 14, 2026

Copy link
Copy Markdown
Member

The v7 default picked a random curated local time zone, which broke DateTime.Now.ToUniversalTime(): the mocked DateTime.Now is stamped DateTimeKind.Local, but its ToUniversalTime() resolves against the real machine TimeZoneInfo.Local (which the mock cannot override), so the round-trip produced a wrong value whenever the mocked zone differed from the machine zone.

The parameterless new MockTimeSystem() and the options-only constructor now use TimeZoneInfo.Local, restoring a correct round-trip by default. A new TimeProviderFactory.Random(TimeZoneInfo localTimeZone) overload keeps the random time while letting callers pick the zone; the existing TimeProviderFactory.Random() still fuzzes the zone from the curated set for anyone who wants that behavior explicitly.

The v7 default picked a random curated local time zone, which broke `DateTime.Now.ToUniversalTime()`: the mocked `DateTime.Now` is stamped `DateTimeKind.Local`, but its `ToUniversalTime()` resolves against the real machine `TimeZoneInfo.Local` (which the mock cannot override), so the round-trip produced a wrong value whenever the mocked zone differed from the machine zone.

The parameterless `new MockTimeSystem()` and the options-only constructor now use `TimeZoneInfo.Local`, restoring a correct round-trip by default. A new `TimeProviderFactory.Random(TimeZoneInfo localTimeZone)` overload keeps the random time while letting callers pick the zone; the existing `TimeProviderFactory.Random()` still fuzzes the zone from the curated set for anyone who wants that behavior explicitly.
@vbreuss vbreuss self-assigned this Jul 14, 2026
@vbreuss vbreuss added the bug Something isn't working label Jul 14, 2026
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Test Results

    122 files  ± 0      122 suites  ±0   2h 20m 40s ⏱️ - 3m 19s
113 459 tests + 1  100 755 ✅ + 1  12 704 💤 ±0  0 ❌ ±0 
283 648 runs  +80  246 510 ✅ +80  37 138 💤 ±0  0 ❌ ±0 

Results for commit 2bbe718. ± Comparison against base commit cf660f9.

@vbreuss
vbreuss merged commit 1da4890 into main Jul 14, 2026
14 checks passed
@vbreuss
vbreuss deleted the feature/mocktimesystem-local-timezone-default branch July 14, 2026 10:28
@github-actions

Copy link
Copy Markdown

This is addressed in release v7.0.1.

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

Labels

bug Something isn't working state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant