[release/6.0] Fix TimeZoneInfo.HasIanaId when using Local Time Zone #58414
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #58326
Backport of #58392 to release/6.0
/cc @tarekgh
Customer Impact
Without this fix, users of
TimeZoneInfo.HasIanaId
can get wrong values when usingTimeZoneInfo.Local
.We have exposed the new property
TimeZoneInfo.HasIanaId
in .NET 6.0. This property tells if the Time Zone object is created with IANA Id. This property returns the correct results except when usingTimeZoneInfo.Local
. The reason is when we initializeTimeZoneInfo.Local
property we clone the object before returning it, but we missed cloningHasIanaId
property inside the returned object. The fix is to ensureHasIanaId
is initialized correctly inTimeZoneInfo.Local
.Testing
I tested this on Windows and Linux. Also, I have run the whole regression tests with the fix without any problem. I added more tests to cover the test gap for the functionality we are fixing here.
Risk
Is low. The fix is scoped to the
HasIanaId
property only which is a newly exposed property in .NET 6.0. The change is well tested and added more tests too.