Reject day of year 366 in a non-leap year instead of rolling over#1329
Open
Sreekant13 wants to merge 1 commit into
Open
Reject day of year 366 in a non-leap year instead of rolling over#1329Sreekant13 wants to merge 1 commit into
Sreekant13 wants to merge 1 commit into
Conversation
The DDD/DDDD tokens and parse_iso validate the day of year with
datetime.strptime("%Y-%j"), which accepts day 366 in a non-leap year and
rolls the result over into January 1 of the following year rather than
rejecting it. That is inconsistent with day 367 and above (rejected), and
surprising because a "day of year" input returns a date in a different
year. Detect the rollover and raise ParserError, matching the existing
out-of-range handling.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1329 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2315 2317 +2
Branches 358 359 +1
=========================================
+ Hits 2315 2317 +2 ☔ View full report in Codecov by Harness. |
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.
Pull Request Checklist
Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:
test_YYYY_DDDDassertion; see below.)toxmatrix locally.)tox -e lintlocally.)masterbranch.Description of Changes
The DDD/DDDD tokens and
parse_isovalidate the day of year withdatetime.strptime("%Y-%j"), which accepts day 366 in a non-leap year and rolls the result over into January 1 of the following year rather than rejecting it. That is inconsistent with day 367 and above (which are rejected), and surprising because a "day of year" input returns a date in a different year than the one parsed.For example,
arrow.get("2023-366", "YYYY-DDD")currently returns2024-01-01, whilearrow.get("2023-367", ...)andarrow.get("2023-456", ...)are rejected with "The provided day of year N is invalid".This detects the rollover and raises
ParserError, matching the existing out-of-range handling: afterstrptime, if the resulting year differs from the parsed year, the day of year is out of range for that year. Leap years are unaffected, soarrow.get("2024-366", "YYYY-DDD")still returns2024-12-31.Note this is a small behavior change.
test_YYYY_DDDDpreviously assertedparse_iso("2017-366") == datetime(2018, 1, 1)with a comment describing the rollover as expected; that assertion is updated to expect aParserError. The parser test suite passes.