Repository navigation
Conversation
…#1127) pop_tz_offset_from_string only recognized offsets with a UTC/GMT prefix or minutes (e.g. "+03:00", "+0300"); a bare, minute-less, unprefixed offset like "+03" was left in the string and mis-tokenized as a stray numeric component, causing "Thu, 19 Jan 2023 10:45:00 +03" to fail to parse and "19 Jan 2023 10:45:00 +03" (no weekday) to parse to the wrong day. Add a dedicated whole-hour bare-offset block to timezone_info_list, anchored on a preceding whitespace character so it can't be confused with a dash-separated date component (e.g. the "-12" day in "2015-04-12"). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1475 +/- ##
=======================================
Coverage 98.94% 98.94%
=======================================
Files 239 239
Lines 3521 3521
=======================================
Hits 3484 3484
Misses 37 37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AdrianAtZyte
left a comment
There was a problem hiding this comment.
I think this can be a single entry in the
replacelist of the first block instead of a new block that repeats the whole table:# +nn, -nn: (r"(?:UTC|GMT)\\(\+|\-)(\d{2}):00", r"(?<=\\s)\\\1\2"),Same behavior for the cases in your tests, the full test suite passes, and the timezone name becomes
UTC\+03:00like for any other whole-hour offset, instead of the regex source\+03.Please, also move the
parsetest cases into the existingtest_parsing_with_utc_offsets, drop the2015-04-12case fromtest_date_parser.py(the one intest_timezone_parser.pyis enough), and drop the comments that reference the issue or the old behavior.
Per review feedback on scrapinghub#1475: use a single (?<=\s) lookbehind entry in the existing replace list instead of a separate timezone_info_list block, and move the "+03"/"-04" parsing cases into the existing test_parsing_with_utc_offsets rather than a standalone test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Thanks for the review! Applied all the suggested changes:
|
…parse_Thu_19_Jan_2023_10_45_00_+03 # Conflicts: # tests/test_date_parser.py # tests/test_timezone_parser.py
serhii73
left a comment
There was a problem hiding this comment.
Reviewed, no blocking issues. LGTM.
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 <noreply@anthropic.com>
Master already parses offsets like +08 and -03 (#1475); this adds a test that pins the behaviour.
Summary
dateparser.parse("Thu, 19 Jan 2023 10:45:00 +03")returnedNone, and the same string without the weekday parsed to the wrong date (day19was replaced by3).pop_tz_offset_from_stringonly recognized UTC offsets that had aUTC/GMTprefix (UTC+03) or included:00/00minutes (+03:00,+0300). A bare, minute-less, prefix-less offset like+03matched none of the existing patterns, so it was left in the string and got mis-tokenized as a stray numeric date component downstream.timezone_info_list(dateparser/timezones.py) covering-12through+14, anchored on a preceding whitespace character so it can't be confused with a dash-separated date component (e.g. the-12day in2015-04-12, which would otherwise be misread as aUTC-12:00offset).Fixes #1127.
Test plan
tests/test_timezone_parser.pyfor offset extraction/stripping (+03,-04, and a non-match on2015-04-12).test_parse_bare_utc_offsettotests/test_date_parser.pycovering the issue's exact strings plus the dash-separated-date false-positive case.pytest tests/, 24275 passed).ruff check .andruff format --check .pass.