Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export default function formatLocale(locale) {
// Convert day-of-week and week-of-year to day-of-year.
if ("V" in d) {
if (d.V < 1 || d.V > 53) return null;
if (!("w" in d)) d.w = 1;
if (!("w" in d)) d.w = "u" in d ? d.u % 7 : 1;
if ("Z" in d) {
week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
Expand Down
11 changes: 11 additions & 0 deletions test/parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ it("timeParse(\"%w %V %G\")(date) parses numeric weekday, week number (ISO) and
assert.deepStrictEqual(p("1 01 2019"), local(2018, 11, 31));
});

it("timeParse(\"%u %V %G\")(date) parses numeric weekday (ISO), week number (ISO) and corresponding year", () => {
const p = timeParse("%u %V %G");
assert.deepStrictEqual(p("1 01 1990"), local(1990, 0, 1));
assert.deepStrictEqual(p("7 01 1990"), local(1990, 0, 7));
assert.deepStrictEqual(p("4 53 1992"), local(1992, 11, 31));
assert.deepStrictEqual(p("5 53 1992"), local(1993, 0, 1));
assert.deepStrictEqual(p("1 01 2019"), local(2018, 11, 31));
assert.deepStrictEqual(p("2 01 2019"), local(2019, 0, 1));
assert.deepStrictEqual(p("7 01 2019"), local(2019, 0, 6));
});

it("timeParse(\"%w %V %g\")(date) parses numeric weekday, week number (ISO) and corresponding two-digits year", () => {
const p = timeParse("%w %V %g");
assert.deepStrictEqual(p("1 01 90"), local(1990, 0, 1));
Expand Down
12 changes: 12 additions & 0 deletions test/utcParse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ it("utcParse(\"%w %V %G\")(date) parses numeric weekday, week number (ISO) and c
assert.strictEqual(p("X 03 2010"), null);
});

it("utcParse(\"%u %V %G\")(date) parses numeric weekday (ISO), week number (ISO) and corresponding year", () => {
const p = utcParse("%u %V %G");
assert.deepStrictEqual(p("1 01 1990"), utc(1990, 0, 1));
assert.deepStrictEqual(p("7 01 1990"), utc(1990, 0, 7));
assert.deepStrictEqual(p("4 53 1992"), utc(1992, 11, 31));
assert.deepStrictEqual(p("5 53 1992"), utc(1993, 0, 1));
assert.deepStrictEqual(p("1 01 2019"), utc(2018, 11, 31));
assert.deepStrictEqual(p("2 01 2019"), utc(2019, 0, 1));
assert.deepStrictEqual(p("7 01 2019"), utc(2019, 0, 6));
assert.strictEqual(p("X 03 2010"), null);
});

it("utcParse(\"%V %Y\")(date) week number (ISO) and year", () => {
const p = utcParse("%V %Y");
assert.deepStrictEqual(p("01 1990"), utc(1990, 0, 1));
Expand Down