Skip to content

Fix "GMT Standard Time" incorrectly interpreted as fixed-offset zone on Android#130340

Open
matouskozak wants to merge 1 commit into
dotnet:mainfrom
matouskozak:matouskozak-android-timezone-repro
Open

Fix "GMT Standard Time" incorrectly interpreted as fixed-offset zone on Android#130340
matouskozak wants to merge 1 commit into
dotnet:mainfrom
matouskozak:matouskozak-android-timezone-repro

Conversation

@matouskozak

Copy link
Copy Markdown
Member

Fixes #126943

Description

On Android, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time") incorrectly returns a UTC-like time zone with no daylight saving time. "GMT Standard Time" is the Windows time zone ID for Great Britain (Europe/London) which observes BST (UTC+1) in summer.

Root Cause

The GetTimeZone method in TimeZoneInfo.Unix.Android.cs has a check for GMT numeric offset zones (like GMT+5, GMT-3) that only verifies the first 3 characters are "GMT":

if (name.Length >= 3 && name[0] == 'G' && name[1] == 'M' && name[2] == 'T')

This incorrectly matches "GMT Standard Time" and treats it as a fixed-offset zone (with offset 0 from ParseGMTNumericZone), preventing the correct fallback to the IANA lookup path.

Fix

Added a check for + or - at position 3 to ensure only actual numeric offset zone names are handled:

if (name.Length >= 4 && name[0] == 'G' && name[1] == 'M' && name[2] == 'T' && (name[3] == '+') || name[3] == '-'))

Testing

  • Added AndroidGMTOffsetTimeZoneTest — verifies GMT+/- offset zones still work correctly
  • Added AndroidGMTNameNotMistakenForGMTOffsetTimeZoneTest — regression test verifying "GMT Standard Time" resolves with DST support
  • Verified on Android emulator (Pixel 8, API 35): before fix returns SupportsDaylightSavingTime: False, after fix returns True with correct UTC+1 offset in summer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adjusts Android’s TimeZoneInfo ID handling so that only true numeric-offset IDs (e.g., GMT+5, GMT-3) are treated as fixed-offset zones, allowing other GMT... Windows IDs (notably GMT Standard Time) to flow to the Windows→IANA conversion path and preserve DST semantics.

Changes:

  • Tighten the Android GetTimeZone fast-path to require GMT+ / GMT- before using the numeric-offset parser.
  • Add Android-only tests to validate GMT+/-N fixed-offset behavior and prevent GMT Standard Time from being misclassified.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.Android.cs Narrows the “GMT numeric offset” detection to avoid misclassifying non-offset GMT... IDs.
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/TimeZoneInfoTests.cs Adds Android-specific coverage for GMT+/- parsing and a regression test for GMT Standard Time DST behavior.

Comment on lines 106 to 113
@@ -107,7 +107,7 @@ private static int ParseGMTNumericZone(string name)
{
return new TimeZoneInfo(id, TimeSpan.FromSeconds(0), id, name, name, null, disableDaylightSavingTime: true);
}
if (name.Length >= 3 && name[0] == 'G' && name[1] == 'M' && name[2] == 'T')
if (name.Length >= 4 && name[0] == 'G' && name[1] == 'M' && name[2] == 'T' && (name[3] == '+' || name[3] == '-'))
{
return new TimeZoneInfo(id, TimeSpan.FromSeconds(ParseGMTNumericZone(name)), id, name, name, null, disableDaylightSavingTime: true);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"GMT0" exists as a real entry in Android's tzdata, so it should load correctly via AndroidTzDataInstance.GetTimeZoneData("GMT0").

@matouskozak matouskozak marked this pull request as draft July 8, 2026 09:11
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Copilot AI review requested due to automatic review settings July 8, 2026 09:33
@matouskozak matouskozak force-pushed the matouskozak-android-timezone-repro branch from 44f468c to 3f86acb Compare July 8, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

@matouskozak matouskozak marked this pull request as ready for review July 8, 2026 10:03
@matouskozak

Copy link
Copy Markdown
Member Author

/azp run runtime-extra-platforms

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

…ndroid

The GMT numeric offset check in GetTimeZone matched any name starting
with "GMT" (e.g. "GMT Standard Time") instead of only names with a
"+" or "-" after "GMT" (e.g. "GMT+5", "GMT-3"). This caused Windows
time zone IDs like "GMT Standard Time" to be resolved as UTC-like
fixed-offset zones with no daylight saving time, instead of falling
through to the IANA lookup path (Europe/London).

Fix: require name[3] to be "+" or "-" before treating as numeric offset.

Added Android-specific tests for both GMT+/- offset zones and the
regression case.

Fixes dotnet#126943

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 14:11
@matouskozak matouskozak force-pushed the matouskozak-android-timezone-repro branch from 3f86acb to b7d9d18 Compare July 8, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment on lines +2571 to +2574

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAndroid), nameof(PlatformDetection.IsIcuGlobalization))]
public static void AndroidGMTNameNotMistakenForGMTOffsetTimeZoneTest()
{
@tarekgh tarekgh added this to the 11.0.0 milestone Jul 8, 2026
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.

Time zone "GMT Standard Time" is incorrectly interpreted on Android

3 participants