Repository navigation
fix(parser): recognize UTC and GMT zone names case-insensitively - #1615
Open
saadkhantareen wants to merge 1 commit into
Open
saadkhantareen wants to merge 1 commit into
saadkhantareen wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
saadkhantareen
force-pushed
the
fix/parser-utc-gmt-case-insensitive
branch
from
October 17, 2026 10:08
9e60310 to
49333c1
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
parser.parse()rejected lowercase and mixed-case UTC zone designations, even though the same designations in uppercase parse fine and every other name lookup in the parser (months, weekdays, AM/PM, andparserinfo.utczone()itself) is case-insensitive:The root cause is in the parser's timezone-name recognition:
_could_be_tzname()only accepted tokens that are entirely uppercase (or literally listed inparserinfo.UTCZONE), soutc,gmt,Utcand similar forms never reached the timezone handling at all. In addition,parserinfo.tzoffset()compared the name against the lowercased_utczonekeys without normalizing case, so it returned0forutcbutNoneforUTC.Fixes #1117
Changes
src/dateutil/parser/_parser.py:_could_be_tzname()now also accepts a token whenparserinfo.utczone()matches it, so UTC zone designations (UTC,GMT,Z) are recognized in any case. Other lowercase tokens (for exampleestorpst) are still not treated as timezone names, exactly as before.src/dateutil/parser/_parser.py:parserinfo.tzoffset()now uses the case-insensitiveutczone()helper instead of a case-sensitive membership test.tests/test_parser.py: added parametrized regression tests covering bare designations in eight case variants (UTC,GMT,utc,gmt,Utc,Gmt,uTc,gMt) and signed-offset forms (utc+3,gmt-5) checked against their uppercase equivalents.changelog.d/1117.bugfix.rst: added a news fragment.AUTHORS.md: added the author.Tests
python -m pytest tests/test_parser.py -k utczone -q: 12 passed.python -m pytest tests/test_parser.py -q: 243 passed, 14 xfailed.python -m pytest tests/ -q(excludingtests/property, which fails to collect in this environment because the zoneinfo data file is not built): 1989 passed, 47 skipped, 17 xfailed, 49 failed. The 49 failures are all intests/test_tz.py, are caused by the same missing zoneinfo data file, and are identical on the unmodified master branch (49 failed, 1977 passed), so this change introduces no new failures.Pull Request Checklist