Clamp the day of month against 31, not 12, in extract_date - #222
Open
arpitjain099 wants to merge 1 commit into
Open
Clamp the day of month against 31, not 12, in extract_date#222arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
extract_date() rejects any day greater than 12 and rewrites it to 01, so every timestamp whose day of month is 13 or later is silently moved to the first of the month. 20121125 comes back as 2012-11-01. The bound looks like a copy of the month check directly above it. Widen it to 31. Days past the end of a short month are already handled downstream by validate_date() in openfda/spl/fix_date.py, which walks them back to a real date instead of discarding them. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
extract_date()inopenfda/common.pyvalidates the day of month against 12:The second bound reads like a copy of the first. The effect is that any day from 13 onward is thrown away and rewritten to the first of the month:
That is roughly 60 percent of all calendar days.
AnnotateLabelinopenfda/spl/annotate.pyfeeds the result straight intolabel['@timestamp'], so SPL effective times land on the wrong day.Days that overflow a short month do not need this guard either.
validate_date()inopenfda/spl/fix_date.pyalready catchesday is out of range for monthand walks the value back to a real date, which is a better outcome than dropping it to the 1st.This widens the bound to 31 and leaves the out-of-range case (
20121132) behaving exactly as before.The existing
test_extract_datecase for day 32 still passes, and I added two cases for valid days past the 12th, which fail on master:With the fix,
python3 -m pytest openfda/tests/common_test.pyis 3 passed.