Open
Description
Description
Upgrading to .NET 7.0 results in (small) DateTime errors when adding seconds (double), probably introduced by #73198.
While it's clear that this cannot be precise for every value it should be precise for values within some range (including the attached example which works flawless in .NET 6.0).
Reproduction Steps
[Fact]
void DateTimeAddSecondsRegression()
{
var dt = DateTime.Parse("2012-09-08T01:22:27.249");
Assert.Equal(dt, dt.Date.AddTicks(Convert.ToInt64(dt.TimeOfDay.TotalSeconds * TimeSpan.TicksPerSecond)));
Assert.Equal(dt, dt.Date.AddSeconds(dt.TimeOfDay.TotalSeconds)); // fails in .NET7
}
Expected behavior
Test should be successful every time.
Actual behavior
Test fails for .NET 7.0 (while successful for .NET 6.0).
Regression?
Yes
Known Workarounds
Workaround: Avoid AddSeconds() method and use your own calculation using ticks.
Configuration
- dotnet 7.0.101
- Windows 10 x64
- Bug is in DateTime.cs (seems to be independent of OS)