[pull] master from scrapinghub:master#94
Merged
Conversation
…h_formats (#1345) When a user-supplied date format contained %j (day of year), parse_with_formats incorrectly treated the parsed date as having no month and no day. This caused it to overwrite the correctly-parsed month and day with the current-date defaults instead of preserving what strptime extracted. Root cause: missing_day was computed as '"%d" not in date_format', missing %j (and %-j) as day-of-year directives. A successful strptime with %j always populates both the day and month fields (e.g. day 100 of 2023 = April 10). The pre-existing _get_missing_parts helper already listed %j in the day directive mapping but not in month. Fix: add %j and %-j to the month directive mapping in _get_missing_parts, and replace the ad-hoc missing_month/missing_day checks in parse_with_formats with _get_missing_parts, which is the authoritative source for this logic. Before: dateparser.parse("2023-100", date_formats=["%Y-%j"]) -> datetime(2023, 6, 25) # wrong: June 25 = today After: dateparser.parse("2023-100", date_formats=["%Y-%j"]) -> datetime(2023, 4, 10) # correct: day 100 of 2023
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )