Fix %V (ISO week) parse to honor %u (ISO weekday)#129
Open
spokodev wants to merge 1 commit into
Open
Conversation
The %V reconstruction (if ("V" in d)) computed the day from d.w only and
defaulted d.w = 1 when %w was absent, ignoring a parsed %u (ISO weekday).
So the canonical ISO 8601 week-date pattern %G-W%V-%u parsed every weekday
to the Monday of its ISO week. The %U/%W branch already reads d.u % 7; apply
the same to the %V branch.
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.
Description
Parsing the canonical ISO 8601 week-date pattern
%G-W%V-%ureturns the wrong day: every weekday collapses to the Monday of its ISO week.Round-trip
parse(format(d))is broken for any day that is not the Monday of its ISO week, which is exactly the case a user reaching for ISO 8601 week dates hits.Root cause
In
src/locale.js, the%Vreconstruction (if ("V" in d)) computes the day fromd.wand defaultsd.w = 1when%wis absent, without consulting a parsed%u(ISO weekday). The sibling%U/%Wbranch already readsd.u % 7. The%Vbranch was never given the same treatment, so%V+%uis the only week + weekday combination that does not work (%V+%wand%U/%W+%uare fine).Fix
Mirrors the existing
%U/%Widiom (d.u % 7, where ISO Sunday7maps to0).Test
Added
%u %V %Gcases to the local and UTC parse tests. They fail before the change (weekday ignored, day lands on Monday) and pass after. Full suite stays green underTZ=America/Los_Angeles(148 passing).