-
Notifications
You must be signed in to change notification settings - Fork 253
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
DateTimeTimeZone ToDateTime returning incorrect parsed date #2286
Comments
Thanks for raising this @chrisportelli,
I believe this may be incorrect behavior for the extension method given that local Any chance you get the correct results if you get the datetime value from the var dateTime = dateTimeTimeZone.ToDateTimeOffset().DateTime;// get the datetime value from DateTimeOffset
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
var cetTime = TimeZoneInfo.ConvertTime(dateTime, timeZoneInfo);
var localTime = TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local); |
Thanks @andrueastman for getting back. That works for us. I'm assuming it's because it sets the date's |
…e contrary to specified timezoneInfo Fixes #2286
Describe the bug
We identified an inconsistent behaviour when using the
DateTimeTimeZone.ToDateTime()
in v4.52.0 of the library across our local and Azure environments. This is used when interacting with the MS Bookings API.From the Graph API, we are calling GET bookingAppointment to get specific appointments. As part of the response it returns the
startDateTime
andendDateTime
, like below (JSON is reduced for brevity):We are using the above
ToDateTime()
extension method to parse this date as aDateTime
object so that we can convert it to CET/CEST, which is the time zone used by the application. However, we are experiencing discrepancies between the returned value of this method for the application running locally (which runs as CET/CEST) and the application deployed to Azure (which runs as UTC).Taking the above example, when running locally as CET/CEST, when calling the extension method the following happens when debugging the method:
DateTime.ParseExact()
converts "2024-01-16T07:30:00.0000000Z" (UTC) to "2024-01-16 08:30" (Local Kind)DateTime.SpecifyKind()
it returns "2024-01-16 08:30" (UTC Kind)When returning the result from the extension method, we are then trying to convert this
DateTime
to a CET/CEST time zone usingTimeZoneInfo.ConvertTime()
which is leading to the time being "2024-01-16 09:30" which is incorrect, as the original "2024-01-16T07:30:00.0000000Z" should be 08:30 in CET/CEST and not 09:30.This does not happen of course in the Azure web app as it is using UTC, however, we have a function app where we are using
WEBSITE_TIME_ZONE
set to "W. Europe Standard Time" and the hours are coming in incorrectly.Can you let us know if this is an issue with the client library or if we are missing or misunderstanding something about the purpose of this extension method?
To Reproduce
Using the SDK v4.52.0 call the extension method as follows from a machine with a time zone that is not aligned with GMT.
Expected behavior
The correct time is returned after parsing the
DateTimeTimeZone.ToDateTime()
.Client version
SDK version 4.52.0 running with .NET 6 (the issue is also replicable in .NET 8 using the same SDK version).
The text was updated successfully, but these errors were encountered: