mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 07:48:12 +00:00
LibJS: Start implementing Date :^)
This adds: - A global Date object (with `length` property and `now` function) - The Date constructor (no arguments yet) - The Date prototype (with `get*` functions)
This commit is contained in:
parent
5c779c124b
commit
d4e3688f4f
25 changed files with 567 additions and 5 deletions
15
Libraries/LibJS/Tests/Date.now.js
Normal file
15
Libraries/LibJS/Tests/Date.now.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var last = 0;
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
var now = Date.now();
|
||||
assert(!isNaN(now))
|
||||
assert(now > 1580000000000);
|
||||
assert(now >= last);
|
||||
last = now;
|
||||
}
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getDate.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getDate.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getDate()));
|
||||
assert(1 <= d.getDate() <= 31);
|
||||
assert(d.getDate() === d.getDate());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getDay.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getDay.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getDay()));
|
||||
assert(0 <= d.getDay() <= 6);
|
||||
assert(d.getDay() === d.getDay());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getFullYear.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getFullYear.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getFullYear()));
|
||||
assert(d.getFullYear() >= 2020);
|
||||
assert(d.getFullYear() === d.getFullYear());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getHours.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getHours.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getHours()));
|
||||
assert(0 <= d.getHours() <= 23);
|
||||
assert(d.getHours() === d.getHours());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getMilliseconds.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getMilliseconds.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getMilliseconds()));
|
||||
assert(0 <= d.getMilliseconds() <= 999);
|
||||
assert(d.getMilliseconds() === d.getMilliseconds());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getMinutes.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getMinutes.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getMinutes()));
|
||||
assert(0 <= d.getMinutes() <= 59);
|
||||
assert(d.getMinutes() === d.getMinutes());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getMonth.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getMonth.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getMonth()));
|
||||
assert(0 <= d.getMonth() <= 11);
|
||||
assert(d.getMonth() === d.getMonth());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getSeconds.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getSeconds.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getSeconds()));
|
||||
assert(0 <= d.getSeconds() <= 59);
|
||||
assert(d.getSeconds() === d.getSeconds());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
11
Libraries/LibJS/Tests/Date.prototype.getTime.js
Normal file
11
Libraries/LibJS/Tests/Date.prototype.getTime.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var d = new Date();
|
||||
assert(!isNaN(d.getTime()));
|
||||
assert(d.getTime() > 1580000000000);
|
||||
assert(d.getTime() === d.getTime());
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue