-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
ManagementDateTimeConverter.ToDateTime returns the wrong DateTimeKind #30128
Comments
CC @Anipik the area owner. The docs https://docs.microsoft.com/en-us/dotnet/api/system.management.managementdatetimeconverter.todatetime?view=netframework-4.8 agree with your that the returned DateTime should be in local time zone. I am wondering, does the DateTime reflect that in all its properties except the Kind property? or the the time is not really adjusted to local timezone at all?
We don't do that except if there is any strong reason. Considering the released 4.8 is the last version of the .NET, I wouldn't expect anything else can be ported there.
If you have any new API suggestion, feel free to open new issue proposing the new APIs. follow the doc https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/api-review-process.md for doing that. |
Yes. All of the properties except the Now that I look at it again, there's also a subtle hidden bug here, in the call to It would be simpler and more correct if the implementation simply constructed a |
…entDateTimeConverter.ToDateTime(string) of NetFX.
The
System.Management.ManagementDateTimeConverter.ToDateTime
method is settingDateTimeKind.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'sKind
property to beDateTimeKind.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 ofTimeZoneInfo.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 aDateTimeOffset
. Otherwise, there's no capability to create a DMTF string that has anything other than the local offset or zero.The text was updated successfully, but these errors were encountered: