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
9 changes: 3 additions & 6 deletions src/scripting_api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,14 @@ class Util {
data.month = parseInt(value) - 1;
},
},
// Weekday names are matched but must not set the day of the month.
dddd: {
pattern: `(${days.join("|")})`,
action: (value, data) => {
data.day = days.indexOf(value);
},
action: () => {},
},
ddd: {
pattern: `(${days.map(day => day.substring(0, 3)).join("|")})`,
action: (value, data) => {
data.day = days.findIndex(day => day.substring(0, 3) === value);
},
action: () => {},
},
dd: {
pattern: "(\\d{2})",
Expand Down
12 changes: 12 additions & 0 deletions test/unit/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,18 @@ describe("Scripting", function () {
expect(value).toEqual([15, 16, 21]);
});

it("should preserve the day of the month when matching weekday names", async () => {
const value = await myeval(`[
util.scand("yyyy-mm-dd ddd", "2026-10-25 Sun").getDate(),
util.scand("yyyy-mm-dd dddd", "2026-10-25 Sunday").getDate(),
util.scand("ddd yyyy-mm-dd", "Sun 2026-10-25").getDate(),
util.scand("dddd yyyy-mm-dd", "Sunday 2026-10-25").getDate(),
util.scand("yyyy-mm-dd ddd", "2026-10-31 Sat").getDate(),
util.scand("ddd yyyy-mm-dd", "Sat 2026-10-31").getDate(),
]`);
expect(value).toEqual([25, 25, 25, 25, 31, 31]);
});

it("should handle a format with repeated specifiers", async () => {
const cFormat = "Hm".repeat(40);
const cDate = `${"1".repeat(84)}x`;
Expand Down