Skip to content

fix: don't invent a day under STRICT_PARSING#1347

Open
apoorva-01 wants to merge 1 commit into
scrapinghub:masterfrom
apoorva-01:fix-strict-parsing-month-year
Open

fix: don't invent a day under STRICT_PARSING#1347
apoorva-01 wants to merge 1 commit into
scrapinghub:masterfrom
apoorva-01:fix-strict-parsing-month-year

Conversation

@apoorva-01

Copy link
Copy Markdown

parse("10/2017", settings={"STRICT_PARSING": True}) gives 2017-10-10 instead of None. Only for YMD locales like zh (en is already fine).

What happens: "10/2017" leaves one spare token ("10") and the back-fill reuses it for both the missing month and day, so the date looks complete and the strict check never fires.

Fix: under STRICT_PARSING/REQUIRE_PARTS, use each leftover token only once. Day stays unset, so it's rejected.

Kept it scoped to the strict path so non-strict output doesn't change (zh still gives 2017-10-10). Wider fix would stop the reuse everywhere and match en at 2017-10-02, but that shifts default behavior, so your call. Happy to widen it.

Tests at the parse() level, fail on master, pass here.

Fixes #850

A YMD locale left a spare token that got reused for both the missing
month and day, so "10/2017" slipped through as 2017-10-10. Only reuse a
leftover token once when parts are enforced.
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.

STRICT_PARSING failed with MM/YYYY format

1 participant