mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[JS] Try to guess what the date is when it doesn't follow the given format (issue #15490)
We use the format to guess in which order we can find month, day, ... we get the numbers in the date and consider them as month, day, ...
This commit is contained in:
parent
547fa3ed2c
commit
9e40938a29
2 changed files with 100 additions and 3 deletions
|
@ -608,14 +608,23 @@ describe("Scripting", function () {
|
|||
it("should parse a date with a format", async () => {
|
||||
const check = async (date, format, expected) => {
|
||||
const value = await myeval(
|
||||
`AFParseDateEx("${date}", "${format}").toISOString()`
|
||||
`AFParseDateEx("${date}", "${format}").toISOString().replace(/T.*$/, "")`
|
||||
);
|
||||
expect(value).toEqual(
|
||||
new Date(expected).toISOString().replace(/T.*$/, "")
|
||||
);
|
||||
expect(value).toEqual(new Date(expected).toISOString());
|
||||
};
|
||||
|
||||
await check("05", "dd", "2000/01/05");
|
||||
await check("12", "mm", "2000/12/01");
|
||||
await check("2022", "yyyy", "2022/01/01");
|
||||
await check("a1$9bbbb21", "dd/mm/yyyy", "2021/09/01");
|
||||
|
||||
// The following test isn't working as expected because
|
||||
// the quickjs date parser has been replaced by the browser one
|
||||
// and the date "1.9.2021" is valid in Chrome but not in Firefox.
|
||||
// The supported date format is not specified...
|
||||
// await check("1.9.2021", "dd/mm/yyyy", "2021/09/01");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue