DateOnly and TimeOnly: retarget net10.0, add conversion samples and tests - #2152
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
DateOnly and TimeOnly: retarget net10.0, add conversion samples and tests#2152vladimir-pecanac-main wants to merge 1 commit into
vladimir-pecanac-main wants to merge 1 commit into
Conversation
…ests Retarget both projects from net6.0 to net10.0 and bring the test packages up to the versions a net10.0 test project needs (Microsoft.NET.Test.Sdk 18.9.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1). Add DemonstrateConversions() covering the DateOnly-to-DateTime direction the sample did not have: ToDateTime(TimeOnly), ToDateTime(TimeOnly.MinValue), ToDateTime(TimeOnly, DateTimeKind), FromDateTime(DateTime.Now) on both types, TimeOnly.FromTimeSpan/ToTimeSpan, DayNumber/FromDayNumber, ParseExact with a fixed format, and AddHours(double, out int). Set CurrentCulture to en-US in Main so the printed output is the same on every machine instead of depending on the host culture. Eleven new xUnit facts cover the additions. The DateTime.Now facts assert round-trip consistency rather than an exact value, because the suite runs at an arbitrary instant.
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.
Retargets
dotnet-datetime/DateOnlyAndTimeOnlyInCSharpto .NET 10 and fills the gap the article's biggest query cluster is asking about: converting betweenDateTime,DateOnly, andTimeOnly.Retarget and packages
net6.0->net10.0.Microsoft.NET.Test.Sdk18.9.0,xunit2.9.3,xunit.runner.visualstudio4.0.0,coverlet.collector10.0.1.New sample code
DemonstrateConversions()on the existingProgram:ToDateTime(TimeOnly),ToDateTime(TimeOnly.MinValue),ToDateTime(TimeOnly, DateTimeKind),DateOnly.FromDateTime(DateTime.Now),TimeOnly.FromDateTime(DateTime.Now),TimeOnly.FromTimeSpan,ToTimeSpan(),DayNumber,FromDayNumber,ParseExact("2022-01-01", "yyyy-MM-dd"), andAddHours(double, out int).CurrentCultureis set toen-USinMainso the printed output does not change with the host machine.Tests
DateTime.Nowfacts assert round-trip consistency rather than a fixed value, since the suite runs at an arbitrary instant.Build is clean: 0 warnings, 0 errors.