Skip to content

Fix %V (ISO week) parse to honor %u (ISO weekday)#129

Open
spokodev wants to merge 1 commit into
d3:mainfrom
spokodev:w32/d3tf-vu-parse
Open

Fix %V (ISO week) parse to honor %u (ISO weekday)#129
spokodev wants to merge 1 commit into
d3:mainfrom
spokodev:w32/d3tf-vu-parse

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown

Description

Parsing the canonical ISO 8601 week-date pattern %G-W%V-%u returns the wrong day: every weekday collapses to the Monday of its ISO week.

d3.utcParse("%G-W%V-%u")("2019-W01-2") // 2018-12-31, should be 2019-01-01
d3.utcParse("%G-W%V-%u")("2019-W01-7") // 2018-12-31, should be 2019-01-06

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 %V reconstruction (if ("V" in d)) computes the day from d.w and defaults d.w = 1 when %w is absent, without consulting a parsed %u (ISO weekday). The sibling %U/%W branch already reads d.u % 7. The %V branch was never given the same treatment, so %V + %u is the only week + weekday combination that does not work (%V + %w and %U/%W + %u are fine).

Fix

-        if (!("w" in d)) d.w = 1;
+        if (!("w" in d)) d.w = "u" in d ? d.u % 7 : 1;

Mirrors the existing %U/%W idiom (d.u % 7, where ISO Sunday 7 maps to 0).

Test

Added %u %V %G cases 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 under TZ=America/Los_Angeles (148 passing).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant