Skip to content

Switch DateTimeKind from Unspecified to Local #90149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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