Honor PREFER_DATES_FROM for a date_formats entry with no year - #1350
Open
chuenchen309 wants to merge 1 commit into
Open
Honor PREFER_DATES_FROM for a date_formats entry with no year#1350chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
parse_with_formats applied PREFER_DATES_FROM only to a two-digit-year format (via _apply_century_preference, added in scrapinghub#1342). A format with no year directive at all just took the current year unconditionally, so parse("December 25", date_formats=["%B %d"], settings={"PREFER_DATES_FROM": "past"}) returned a future date -- contradicting the setting, and disagreeing with the NLP path, which parses the same string correctly. Generalise the helper to shift by ±N years and call it with 1 for the year-less branch (100 stays for the two-digit branch), so both share the same direction and Feb-29 leap-year handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
Contributor
|
Ask your human to explain the fix to me in their words. |
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.
parse_with_formatsappliedPREFER_DATES_FROMonly to a two-digit-year format(through
_apply_century_preference, added in #1342). Adate_formatsentrywith no year directive at all took the current year unconditionally:
The result contradicts the setting, and disagrees with the NLP path, which
parses the same string+settings correctly to
2025-12-25.docs/settings.rststates
PREFER_DATES_FROMapplies "if date string is missing some part" (itsexample omits the year), with no carve-out for
date_formats. This is theother half of #1342 — that PR wired the setting into the adjacent two-digit-year
branch but left the year-less branch.
Fix: generalise the
#1342helper to shift by ±N years and call it with1for the year-less branch (
100stays for the two-digit branch), so both sharethe same direction logic and Feb-29 leap-year handling. Added a regression test.
This PR was authored by an AI coding agent (Claude Code) running on this account:
the AI found the bug, ran the repro, wrote the test, and wrote this description.
The human account holder reviews every change and is accountable for it. The
verification is real and re-runnable from the diff. If this isn't the kind of
contribution you want, say so and I'll close it.