From 9add36e2af2216336b51f7eb2c3c7ac02bd7a674 Mon Sep 17 00:00:00 2001 From: Jackson Benete Date: Mon, 12 Feb 2024 12:32:41 +0000 Subject: [PATCH] add custom date object --- src/kernel.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/kernel.js b/src/kernel.js index 3494673a..8c7dbb71 100644 --- a/src/kernel.js +++ b/src/kernel.js @@ -5,6 +5,16 @@ let userList = []; let mailList = []; let cmdLine_; let output_; +let serverDate = {day: "", month: "", year: "", reference: ""}; + +function initDateObject() { + const date = new Date(); + let day = serverDatabase.day ? serverDatabase.day : date.getDate(); + let month = serverDatabase.month ? serverDatabase.month : date.getMonth() + 1; + let year = serverDatabase.year ? serverDatabase.year : date.getFullYear(); + let reference = serverDatabase.reference ? serverDatabase.reference : "(Solar System Standard Time)" + serverDate = {day: day, month: month, year: year, reference: reference} +} function debugObject( obj ) { for ( const property in obj ) { @@ -22,13 +32,10 @@ function debugObject( obj ) { */ function setHeader( msg = "⠀" ) { // Setting correct header icon and terminal name - const date = new Date(); - if ( serverDatabase.year ) { - date.setYear( serverDatabase.year ); - } const promptText = `[${ userDatabase.userName }@${ serverDatabase.terminalID }] # `; - const dateStr = `${ date.getDate() }/${ ( 1 + date.getMonth() ).toString().padStart( 2, "0" ) }/${ 1900 + date.getYear() }`; + initDateObject() + const dateStr = serverDate.day + "/" + serverDate.month + "/" + serverDate.year const header = `

${ serverDatabase.serverName }

@@ -282,11 +289,9 @@ system = { date() { return new Promise( ( resolve ) => { - const date = new Date(); - if ( serverDatabase.year ) { - date.setYear( serverDatabase.year ); - } - resolve( String( date ) ); + let date = new Date(); + let time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + resolve( String( serverDate.month + " " + serverDate.day + " " + serverDate.year + " " + time + " " + serverDate.reference ) ); } ); },