Skip to content

ManagementDateTimeConverter.ToDateTime returns the wrong DateTimeKind #30128

Closed
@mattjohnsonpint

Description

@mattjohnsonpint

The System.Management.ManagementDateTimeConverter.ToDateTime method is setting DateTimeKind.Unspecified in the result here.

I believe this to be incorrect, as it explicitly adjusts the time to the local computer's offset. As a user of this API, I'd expect the resulting DateTime value's Kind property to be DateTimeKind.Local.

With unspecified kind, I'd expect the result to not have been adjusted to the local time zone.

Also, a couple of other observations about the ManagementDateTimeConverter class:

  • The fixes from May 2018 seen in the history don't appear to have been ported back to .NET Framework. For example, I can see that in the NetFX implementation it still uses TimeZone.CurrentTimeZone instead of TimeZoneInfo.Local.

  • It would seem prudent to make a ToDateTimeOffset method that retains the offset provided in the DMTF string. Otherwise the user has to go out of their way to parse the string again manually to obtain the original offset.

  • Likewise, it would seem prudent to have an overload of ToDMTFDateTime that accepts a DateTimeOffset. Otherwise, there's no capability to create a DMTF string that has anything other than the local offset or zero.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions