Skip to content

Conversation

@tarekgh
Copy link
Member

@tarekgh tarekgh commented Oct 25, 2025

Fixes #117422

We maintain an internal cache, _systemTimeZones, that maps time zone IDs to their corresponding TimeZoneInfo objects. Entries are added when either TimeZoneInfo.GetSystemTimeZones(...) or TimeZoneInfo.FindSystemTimeZoneById(...) is called.

On Linux and macOS, TimeZoneInfo.FindSystemTimeZoneById(...) attempts to retrieve the time zone object by reading the appropriate time zone file (for example, /usr/share/zoneinfo/America/Los_Angeles for Pacific Time). When TimeZoneInfo.GetSystemTimeZones() is called, it reads the list of available time zones from the /usr/share/zoneinfo/zone.tab file. This file provides a filtered list that excludes legacy time zones and avoids duplicate entries with different IDs.

The issue arises when TimeZoneInfo.FindSystemTimeZoneById(...) is called with a legacy time zone ID that is not listed in zone.tab. In that case, the corresponding time zone object is still created and added to the _systemTimeZones cache. Later, when TimeZoneInfo.GetSystemTimeZones(...) is invoked, the list populated from zone.tab may include a duplicate time zone (same display name but different ID), such as both UTC and UCT. This can cause problems for UI applications that display time zone names, as duplicates appear in the list.

The fix ensures that GetSystemTimeZones() returns only the filtered list derived from zone.tab, excluding any cached entries added from legacy or non-standard sources. This approach preserves cache consistency and performance, while preventing duplicates from appearing in the final list.

Windows systems are not affected by this issue, so the change will have minimal impact there aside from shared code adjustments.

Copilot AI review requested due to automatic review settings October 25, 2025 23:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where TimeZoneInfo.GetSystemTimeZones() on Linux/macOS could return duplicate time zones with different IDs (e.g., "UTC" and "UCT"). The root cause was that legacy time zone IDs loaded via FindSystemTimeZoneById() were being included in the results even though they weren't in the filtered zone.tab list.

Key changes:

  • Modified PopulateAllSystemTimeZones() to return a filtered dictionary instead of void
  • Separated the internal cache (_systemTimeZones) from the filtered list returned to callers
  • Updated tests to verify no duplicates appear and removed the Linux-specific test skip

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
System/TimeZoneInfo.cs Updated GetSystemTimeZones() to use filtered list from PopulateAllSystemTimeZones() instead of the internal cache directly
System/TimeZoneInfo.Win32.cs Changed PopulateAllSystemTimeZones() to return the system time zones dictionary (no filtering needed on Windows)
System/TimeZoneInfo.Unix.cs Implemented filtering logic to return only time zones from zone.tab, excluding cached legacy entries
System/TimeZoneInfoTests.cs Added comprehensive test coverage and removed Linux platform skip for duplicate detection test

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-datetime
See info in area-owners.md if you want to be subscribed.

@tarekgh
Copy link
Member Author

tarekgh commented Oct 26, 2025

It seems the test is no longer failing now on Linux platforms either.

@tarekgh
Copy link
Member Author

tarekgh commented Oct 27, 2025

@stephentoub just checking if you have any more feedback on this PR. Thanks!

@tarekgh
Copy link
Member Author

tarekgh commented Oct 27, 2025

/ba-g the failing tests are unrelated timing out and showing in other PRs too.

@tarekgh tarekgh merged commit b3a8d0d into dotnet:main Oct 27, 2025
138 of 143 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoBackwardTimeZones fails on macOS 26 Preview 3

3 participants