DateTime.Now vs DateTime.UtcNow: retarget net10.0, bump test packages, add Unspecified conversion tests - #2150
Merged
vladimir-pecanac-main merged 2 commits intoAug 31, 2026
Conversation
…, add Unspecified conversion tests - Both projects net6.0 -> net10.0 - Microsoft.NET.Test.Sdk 16.11.0 -> 18.9.0, MSTest 2.2.7 -> 4.3.3, coverlet.collector 3.1.0 -> 10.0.1 - Two tests pinning the DateTimeKind.Unspecified asymmetry: ToLocalTime() treats an unspecified value as UTC, ToUniversalTime() treats it as local. Written offset-agnostic so they hold in a UTC CI container.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supports the republish of Difference Between DateTime.Now and DateTime.UtcNow in C#.
What changed in
dotnet-datetime/DateTimeNowVsDateTimeUtcNow:net6.0->net10.0. Console project and test project.Microsoft.NET.Test.Sdk16.11.0 -> 18.9.0,MSTest.TestAdapter/MSTest.TestFramework2.2.7 -> 4.3.3,coverlet.collector3.1.0 -> 10.0.1. Versions re-read from the NuGet flat-container API on 2026-08-30; a net6.0-era Test SDK will not run a net10.0 test project, so the bump is required by (1) rather than cosmetic.DateTimeTestsclass pinning theDateTimeKind.Unspecifiedasymmetry that the article's conversion section documents:ToLocalTime()treats an unflagged value as if it were UTC, whileToUniversalTime()treats the same value as if it were local. Both are written offset-agnostic (equality againstSpecifyKind(Utc)/SpecifyKind(Local)) so they hold in a UTC CI container as well as on a machine with a non-zero offset.No change to
Program.cs: it is already top-level statements with implicit usings, and every snippet printed in the article matches it.Verified locally on SDK 10.0.302:
dotnet build -c Releasesucceeds,dotnet test -c Releasepasses 7/7.Note: the MSTest 4.x analyzers report two
MSTEST0017warnings (swapped expected/actual arguments) on two pre-existing assertions inDateTimeTests.cs. They are warnings only, they predate this PR, and they are left untouched to keep the diff to what the article needs.