Skip to content

Fix timezone parser ignoring Unicode dash-like UTC offset characters - #1474

Merged
AdrianAtZyte merged 2 commits into
scrapinghub:masterfrom
yamilmaud:fix_DC-1304_Timezone_parser_fails_on_hyphen_like_characters
Sep 29, 2026
Merged

AdrianAtZyte merged 2 commits into
scrapinghub:masterfrom
yamilmaud:fix_DC-1304_Timezone_parser_fails_on_hyphen_like_characters

Conversation

@yamilmaud

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Timezone parser fails on hyphen-like characters #1126: dateparser.parse("jan 15th UTC−06:00") (using U+2212 MINUS SIGN, as Wikipedia's List of UTC offsets does) silently dropped the offset instead of parsing it, because the UTC/GMT offset regexes only match the ASCII hyphen-minus -.
  • Normalizes the full set of Unicode Dash Characters (per the Unicode Standard's Dash property table) to ASCII hyphen-minus in sanitize_date(), mirroring the existing apostrophe-look-alike normalization already in that function.
  • Positive offsets (UTC+01:00) are unaffected — they already used, and still use, plain ASCII +.

Test plan

  • Added TestSanitizeDate.test_sanitize_date_dash_look_alikes (unit test on sanitize_date, iterating the full dash character list).
  • Added TestUnicodeDashOffsets in tests/test_timezone_parser.py (end-to-end dateparser.parse() test reproducing the issue's example plus other dash variants).
  • Full test suite passes: pytest tests/ (24274 passed, 6 skipped, 1 xfailed).
  • ruff check / ruff format --check clean on changed files.

🤖 Generated with Claude Code

Sources like Wikipedia's UTC offset list typographically render negative
offsets with Unicode dash characters (e.g. U+2212 MINUS SIGN) instead of
ASCII hyphen-minus, which the UTC/GMT offset regexes never matched, so the
offset was silently dropped (fixes scrapinghub#1126).

Normalize the full set of Unicode Dash Characters (per the Unicode Standard's
Dash property table) to ASCII hyphen-minus in sanitize_date(), mirroring the
existing apostrophe-look-alike normalization.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@codspeed

codspeed Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing yamilmaud:fix_DC-1304_Timezone_parser_fails_on_hyphen_like_characters (b6521f6) with master (ef140a8)

Open in CodSpeed

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.21%. Comparing base (ef140a8) to head (b6521f6).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1474   +/-   ##
=======================================
  Coverage   97.21%   97.21%           
=======================================
  Files         236      236           
  Lines        3090     3093    +3     
=======================================
+ Hits         3004     3007    +3     
  Misses         86       86           

☔ 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.

Some recently-added dash characters (e.g. Garay Hyphen, Yezidi
Hyphenation Mark, Oblique Hyphen) aren't in the unicodedata name
tables bundled with older Python versions, so \N{...} escapes for
them raised a SyntaxError on Python 3.10 in CI. \u/\U hex escapes
only need the codepoint, not a name lookup, so they work regardless
of the interpreter's Unicode database version.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Comment thread dateparser/date.py
Comment on lines +40 to +44
# Unicode Dash Characters, per the "Dash" property table in the Unicode Standard
# (https://www.unicode.org/versions/latest/core-spec/chapter-6/#G9697), excluding
# U+002D HYPHEN-MINUS itself. Written as \u/\U escapes rather than \N{...} names
# since some of these (e.g. Garay Hyphen, Yezidi Hyphenation Mark) are recent
# Unicode additions not present in the unicodedata name tables of older Pythons.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment could just be the URL 🙂

@AdrianAtZyte
AdrianAtZyte merged commit 3ec5fe3 into scrapinghub:master Sep 29, 2026
18 checks passed
@serhii73 serhii73 mentioned this pull request Sep 30, 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.

Timezone parser fails on hyphen-like characters

2 participants