Skip to content

DateTime.Now vs DateTime.UtcNow: retarget net10.0, bump test packages, add Unspecified conversion tests - #2150

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/64656-now-utcnow
Aug 31, 2026
Merged

DateTime.Now vs DateTime.UtcNow: retarget net10.0, bump test packages, add Unspecified conversion tests#2150
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/64656-now-utcnow

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Supports the republish of Difference Between DateTime.Now and DateTime.UtcNow in C#.

What changed in dotnet-datetime/DateTimeNowVsDateTimeUtcNow:

  1. Retarget both projects net6.0 -> net10.0. Console project and test project.
  2. Bump the test packages. Microsoft.NET.Test.Sdk 16.11.0 -> 18.9.0, MSTest.TestAdapter / MSTest.TestFramework 2.2.7 -> 4.3.3, coverlet.collector 3.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.
  3. Two new tests in the existing DateTimeTests class pinning the DateTimeKind.Unspecified asymmetry that the article's conversion section documents: ToLocalTime() treats an unflagged value as if it were UTC, while ToUniversalTime() treats the same value as if it were local. Both are written offset-agnostic (equality against SpecifyKind(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 Release succeeds, dotnet test -c Release passes 7/7.

Note: the MSTest 4.x analyzers report two MSTEST0017 warnings (swapped expected/actual arguments) on two pre-existing assertions in DateTimeTests.cs. They are warnings only, they predate this PR, and they are left untouched to keep the diff to what the article needs.

…, 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.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 02452c5 into CodeMazeBlog:main Aug 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant