Skip to content

Commit

Permalink
Improve date parsing in the js sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Jun 11, 2024
1 parent 341ff40 commit 7ada0f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/scripting_api/aform.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ class AForm {
try {
date = this._util.scand(cFormat, cDate);
} catch {}
if (!date) {
let format = cFormat;
if (format.search(/mm(?!m)/) !== -1) {
format = format.replace("mm", "m");
}
if (format.search(/dd(?!d)/) !== -1) {
format = format.replace("dd", "d");
}
try {
date = this._util.scand(format, cDate);
} catch {}
}
if (!date) {
date = Date.parse(cDate);
date = isNaN(date)
Expand Down
4 changes: 4 additions & 0 deletions test/unit/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ describe("Scripting", function () {
await check("12", "mm", "2000/12/01");
await check("2022", "yyyy", "2022/01/01");
await check("a1$9bbbb21", "dd/mm/yyyy", "2021/09/01");
await check("1/2/2024", "dd/mm/yyyy", "2024/02/01");
await check("01/2/2024", "dd/mm/yyyy", "2024/02/01");
await check("1/02/2024", "dd/mm/yyyy", "2024/02/01");
await check("01/02/2024", "dd/mm/yyyy", "2024/02/01");

// The following test isn't working as expected because
// the quickjs date parser has been replaced by the browser one
Expand Down

0 comments on commit 7ada0f7

Please sign in to comment.