MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1let failed = 0;
2
3function check(label, cond, detail) {
4 if (!cond) {
5 failed++;
6 console.log("FAIL", label, detail || "");
7 }
8}
9
10const msZ = Date.parse("2026-02-27T12:00:00Z");
11check("Date.parse Z", msZ === 1772193600000, msZ);
12
13const dZ = new Date("2026-02-27T12:00:00Z");
14check("new Date Z toISOString", dZ.toISOString() === "2026-02-27T12:00:00.000Z", dZ.toISOString());
15
16const dDateOnly = new Date("2026-02-27");
17check("date-only is UTC midnight", dDateOnly.toISOString() === "2026-02-27T00:00:00.000Z", dDateOnly.toISOString());
18
19const dClone = new Date(dZ);
20check("clone from Date object", dClone.getTime() === dZ.getTime(), dClone.getTime() + " vs " + dZ.getTime());
21
22const msOff = Date.parse("2026-02-27T12:00:00+02:30");
23const msOffRef = Date.parse("2026-02-27T09:30:00Z");
24check("timezone offset", msOff === msOffRef, msOff + " vs " + msOffRef);
25
26const invalidParse = Date.parse("not-a-date");
27check("invalid parse is NaN", invalidParse !== invalidParse, invalidParse);
28
29const invalidDate = new Date("not-a-date");
30const invalidTime = invalidDate.getTime();
31check("invalid date getTime is NaN", invalidTime !== invalidTime, invalidTime);
32
33if (failed > 0) throw new Error("test_date_parse_string failed");