Skip to content

Commit

Permalink
Switch DateTimeKind from Unspecified to Local (#90149)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksim Golev <mgolev@htc-cs.ru>
  • Loading branch information
Maximys and Maksim Golev authored Aug 14, 2023
1 parent 5d8dc41 commit a666f59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ public static DateTime ToDateTime(string dmtfDate)
}


// Construct a new System.DateTime object, .NET Framework uses date kind unspecified so use the same
var datetime = new DateTime(year, month, day, hour, minute, second, 0, DateTimeKind.Unspecified);
var datetime = new DateTime(year, month, day, hour, minute, second, 0, DateTimeKind.Local);
// Then add the ticks calculated from the microseconds
datetime = datetime.AddTicks(ticks);
// Then adjust the offset, using a manual calulation to keep the same possible range as netfx
// Then adjust the offset, using a manual calculation to keep the same possible range as netfx
datetime = datetime.AddMinutes(-(utcOffset - TimeZoneInfo.Local.GetUtcOffset(datetime).Ticks / TimeSpan.TicksPerMinute));

return datetime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ public void DateTime_MinValue_RoundTrip()
{
string dmtfFromDateTimeMinValue = ManagementDateTimeConverter.ToDmtfDateTime(DateTime.MinValue);
DateTime convertedDate = ManagementDateTimeConverter.ToDateTime(dmtfFromDateTimeMinValue);
Assert.Equal(DateTimeKind.Unspecified, convertedDate.Kind);
if (PlatformDetection.IsNetFramework)
{
Assert.Equal(DateTimeKind.Unspecified, convertedDate.Kind);
}
else
{
Assert.Equal(DateTimeKind.Local, convertedDate.Kind);
}
Assert.Equal(DateTime.MinValue, convertedDate);
}

Expand Down

0 comments on commit a666f59

Please sign in to comment.