fix(parser): preserve sign for UTC/GMT/Z offset notation#1479
Open
BlocksecPHD wants to merge 3 commits intodateutil:masterfrom
Open
fix(parser): preserve sign for UTC/GMT/Z offset notation#1479BlocksecPHD wants to merge 3 commits intodateutil:masterfrom
BlocksecPHD wants to merge 3 commits intodateutil:masterfrom
Conversation
added 3 commits
April 9, 2026 05:10
Previously, UTC/GMT/Z followed by +/- offset incorrectly used POSIX convention reversal, causing 'UTC-4' to be parsed as +04:00 instead of -04:00. For timezone abbreviations like 'BRST+3', the POSIX convention is correct (the timezone is UTC-3). But for UTC offset notation like 'UTC-4', the sign should be literal (UTC minus 4 hours). This fix distinguishes between UTC zone names (UTC, GMT, Z) and other timezone abbreviations, preserving the literal sign for the former while keeping POSIX convention for the latter. Fixes dateutil#1478
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.
Problem
When parsing datetime strings like
'2026-03-11 14:32:45 UTC-4', the parser incorrectly reversed the offset sign, resulting in+04:00instead of the expected-04:00.Root Cause
The parser applied POSIX timezone convention to UTC zone names (UTC, GMT, Z). In POSIX,
EST5means the timezone is UTC-5 (not UTC+5), andGMT+3would mean UTC-3. However, modern UTC offset notation like'UTC-4'should mean UTC minus 4 hours literally, not POSIX convention.Fix
This PR distinguishes between UTC zone names (UTC, GMT, Z) and other timezone abbreviations:
'UTC-4'→-04:00)Test Cases
Added regression test
test_utc_offset_not_reversedcovering various UTC/GMT/Z offset combinations.Fixes: #1478