Skip to content

Support short UTC offset timezones - #1340

Merged
serhii73 merged 2 commits into
scrapinghub:masterfrom
CodingFeng101:codex/support-short-utc-offset
Oct 20, 2026
Merged

serhii73 merged 2 commits into
scrapinghub:masterfrom
CodingFeng101:codex/support-short-utc-offset

Conversation

@CodingFeng101

Copy link
Copy Markdown
Contributor

Summary

Support two-digit UTC offset timezone strings such as +08 and -03 when they are passed through timezone settings. These values are produced by Python's timezone APIs on some systems, but currently raise UnknownTimeZoneError while equivalent forms like UTC+08, +0800, and +08:00 are accepted.

Changes

  • Normalize +HH / -HH timezone strings to the existing UTC+HH matching path.
  • Add focused regression coverage for positive and negative short UTC offsets.

Validation

  • python -m pytest tests/test_short_utc_offsets.py -q -> 2 passed
  • Manual smoke check confirmed dateparser.parse(..., settings={"TIMEZONE": "+08"}) and "-03" no longer raise.

@codecov

codecov Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (08c78d3) to head (03bda05).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1340   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files         235      235           
  Lines        2909     2911    +2     
=======================================
+ Hits         2825     2827    +2     
  Misses         84       84           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@serhii73 serhii73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR. This now has merge conflicts, and current master already parses bare two-digit offsets: get_timezone_from_tz_string('+08') returns UTC+08:00 and parse('2024-05-01 10:00 +08') gives +08:00 (added in #1475). I'm not merging it as is. If you still need something it doesn't cover, please rebase and add a failing case, otherwise it can be closed as superseded.

Master already parses bare two-digit offsets (scrapinghub#1475), so the
get_timezone_from_tz_string change is dropped and only the regression
test is kept.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

@serhii73 serhii73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Merged master into the branch and dropped the get_timezone_from_tz_string change, because #1475 already parses bare two-digit offsets. The PR is now test-only: it pins +08 and -03. Full suite passes (24885 passed). Code review found no correctness issues. Non-blocking: the test could also cover the TIMEZONE setting through parse() and boundary offsets, and could live in tests/test_utils.py.

@serhii73
serhii73 merged commit eb27abd into scrapinghub:master Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants