You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: MockTimeProvider constructor treats "now" having DateTimeKind.Unspecified as if it had DateTimeKind.Local (#834)
The difference between `DateTime.Now` And `DateTime.UtcNow` should be the offset from the local time zone to UTC. Before this change, `MockTimeSystem` would produce a difference double that size when initialized with a `DateTime` having `Kind` `DateTimeKind.Unspecified`.
The `MockTimeSystem` delegates to a `MockDateTime` wrapped around a `TimeProviderMock`. The `TimeProviderMock` would yield a `DateTime` with `Kind` `DateTimeKind.Unspecified` to the `MockDateTime`, which would then apply `ToLocalTime()` for `Now` or `ToUniversalTime` for `UtcNow`. When applied to a `DateTime` with `Kind` `DateTimeKind.Unspecified`, `ToLocalTime` assumes that the value is in UTC, but `ToUniversalTime` assumes that it is Local. This discrepancy results in the doubling of the expected difference.
Additionally, the test `OnDateTimeRead_Today_ShouldExecuteCallbackWithCorrectParameter` was failing, but only when run on systems outside of UTC. On systems running inside UTC, there was no difference between `Now` and `UtcNow`, so the error was hidden.
So, when the `MockTimeSystem` is initialized with a `DateTime` which has `Kind` `DateTimeKind.Unspecified`, it should pick a specific kind to use internally. Either `Utc` or `Local` would work.
`Utc` was selected because local times often lead to tests that only work in a specific time zone and should be selected intentionally.
0 commit comments