1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 13:45:06 +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:
Linus Groh 2020-03-30 00:21:56 +01:00 committed by Andreas Kling
parent 5c779c124b
commit d4e3688f4f
25 changed files with 567 additions and 5 deletions

29
Base/home/anon/js/date.js Normal file
View file

@ -0,0 +1,29 @@
var now = Date.now();
console.log("Unix timestamp: " + now / 1000);
// FIXME: We need String.prototype.padStart() :^)
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
if (month < 10)
month = "0" + month;
var day = d.getDate();
if (day < 10)
day = "0" + day;
var hours = d.getHours();
if (hours < 10)
hours = "0" + hours;
var minutes = d.getMinutes();
if (minutes < 10)
minutes = "0" + minutes;
var seconds = d.getSeconds();
if (seconds < 10)
seconds = "0" + seconds;
var milliseconds = d.getMilliseconds();
if (milliseconds < 10) {
milliseconds = "00" + milliseconds;
} else if (milliseconds < 100) {
milliseconds = "0" + milliseconds;
}
console.log("Date: " + year + "-" + month + "-" + day);
console.log("Time: " + hours + ":" + minutes + ":" + seconds + "." + milliseconds);