Conversation
If a weekday is specified and a week number is not specified, verify that the parsed weekday matches the weekday implied by the date, and return null if it does not.
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.
locale.parseaccepts a weekday that contradicts the date it is parsed alongside.%a %m/%d/%Yon"Tue 01/01/1990"returns 1 January 1990, a Monday, rather than null. Per #29 a specified weekdaythat does not match the implied date should fail the parse.
src/locale.jsonly consulted the weekday when a week number was present, because that is the casewhere it contributes to the date. When it is redundant it was ignored rather than checked. This adds
the else branch: with a weekday but no week number, compute the day the parsed date falls on and
return null when the two disagree.
%uis compared modulo 7, since ISO numbers Sunday as 7 wheregetDayuses 0.Existing tests had to change, and it is worth being explicit about why rather than leaving it to the
diff:
"Sun 01/01/1990"and"Wed 02/03/1991"were both asserting successful parses of dates whoseweekday is wrong. 1 January 1990 was a Monday and 3 February 1991 a Sunday. They now use the correct
weekday, and a mismatching case asserts null.
Fixes #30