Fix "GMT Standard Time" incorrectly interpreted as fixed-offset zone on Android#130340
Fix "GMT Standard Time" incorrectly interpreted as fixed-offset zone on Android#130340matouskozak wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
GetTimeZonefast-path to requireGMT+/GMT-before using the numeric-offset parser. - Add Android-only tests to validate
GMT+/-Nfixed-offset behavior and preventGMT Standard Timefrom 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. |
| @@ -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); | |||
| } | |||
There was a problem hiding this comment.
"GMT0" exists as a real entry in Android's tzdata, so it should load correctly via AndroidTzDataInstance.GetTimeZoneData("GMT0").
|
Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger |
44f468c to
3f86acb
Compare
|
/azp run runtime-extra-platforms |
|
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>
3f86acb to
b7d9d18
Compare
|
|
||
| [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAndroid), nameof(PlatformDetection.IsIcuGlobalization))] | ||
| public static void AndroidGMTNameNotMistakenForGMTOffsetTimeZoneTest() | ||
| { |
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
GetTimeZonemethod inTimeZoneInfo.Unix.Android.cshas a check for GMT numeric offset zones (likeGMT+5,GMT-3) that only verifies the first 3 characters are "GMT":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:Testing
AndroidGMTOffsetTimeZoneTest— verifies GMT+/- offset zones still work correctlyAndroidGMTNameNotMistakenForGMTOffsetTimeZoneTest— regression test verifying "GMT Standard Time" resolves with DST supportSupportsDaylightSavingTime: False, after fix returnsTruewith correct UTC+1 offset in summer