diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/Date/parse-from-tostring-methods.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Date/parse-from-tostring-methods.js')
-rw-r--r-- | js/src/tests/non262/Date/parse-from-tostring-methods.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/js/src/tests/non262/Date/parse-from-tostring-methods.js b/js/src/tests/non262/Date/parse-from-tostring-methods.js new file mode 100644 index 0000000000..b6bf577bb0 --- /dev/null +++ b/js/src/tests/non262/Date/parse-from-tostring-methods.js @@ -0,0 +1,31 @@ +let dates = [ + "0041-09-23", "+000041-09-23", "-000041-09-23", + "0091-09-23", "+000091-09-23", "-000091-09-23", + "0217-09-23", "+000217-09-23", "-000217-09-23", + "2017-09-23", "+002017-09-23", "-002017-09-23", + "+022017-09-23", "-022017-09-23", + "+202017-09-23", "-202017-09-23", +]; + +for (let date of dates) { + let d = new Date(date); + let timeValue = d.valueOf(); + + assertEq(Number.isNaN(timeValue), false, `Cannot parse "${date}" as ISO date-only form`); + + // Ensure parsing the results of toString(), toUTCString(), and toISOString() + // gives the same time value as required by 20.3.3.2 Date.parse. + // + // Additional requirement not present in ES2019 draft rev 7acacc524213058a2368b5fa751fac7ea08ba230: + // The time zone offset must not contain seconds (or milliseconds) for |Date.parse(x.toString())| + // to be equal to |x.valueOf()|. + let tz = d.getTimezoneOffset(); + if (Math.trunc(tz) === tz) { + assertEq(Date.parse(d.toString()), timeValue, `Cannot parse from toString() of "${date}"`); + } + assertEq(Date.parse(d.toUTCString()), timeValue, `Cannot parse from toUTCString() of "${date}"`); + assertEq(Date.parse(d.toISOString()), timeValue, `Cannot parse from toISOString() of "${date}"`); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |