diff --git a/src/Script.js b/src/Script.js index 61f24cc4c..93f03a373 100644 --- a/src/Script.js +++ b/src/Script.js @@ -24,12 +24,12 @@ import {iTutorialSteps, iTutorialNextStep, iTutorialIsRunning, currITutorialStep} from "./InteractiveTutorial"; import {evaluateImport} from "./NetscriptEvaluator"; import {NetscriptFunctions} from "./NetscriptFunctions"; -import {addWorkerScript, killWorkerScript, +import {addWorkerScript, WorkerScript} from "./NetscriptWorker"; import {Player} from "./Player"; import {AllServers, processSingleServerGrowth} from "./Server"; import {Settings} from "./Settings"; -import {post, Terminal} from "./Terminal"; +import {post} from "./Terminal"; import {TextFile} from "./TextFile"; import {parse, Node} from "../utils/acorn"; @@ -39,6 +39,7 @@ import {Reviver, Generic_toJSON, import {compareArrays} from "../utils/helpers/compareArrays"; import {createElement} from "../utils/uiHelpers/createElement"; import {formatNumber} from "../utils/StringHelperFunctions"; +import {getTimestamp} from "../utils/helpers/getTimestamp"; import {roundToTwo} from "../utils/helpers/roundToTwo"; var keybindings = { @@ -962,7 +963,7 @@ RunningScript.prototype.log = function(txt) { } let logEntry = txt; if (FconfSettings.ENABLE_TIMESTAMPS) { - logEntry = "[" + Terminal.getTimestamp() + "] " + logEntry; + logEntry = "[" + getTimestamp() + "] " + logEntry; } this.logs.push(logEntry); this.logUpd = true; diff --git a/src/Terminal.js b/src/Terminal.js index 3febac5c1..dca7e4f77 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -38,6 +38,7 @@ import {containsAllStrings, longestCommonStart, import {addOffset} from "../utils/helpers/addOffset"; import {isString} from "../utils/helpers/isString"; import {arrayToString} from "../utils/helpers/arrayToString"; +import {getTimestamp} from "../utils/helpers/getTimestamp"; import {logBoxCreate} from "../utils/LogBox"; import {yesNoBoxCreate, yesNoBoxGetYesButton, @@ -115,7 +116,7 @@ $(document).keydown(function(event) { if (command.length > 0) { post( "[" + - (FconfSettings.ENABLE_TIMESTAMPS ? Terminal.getTimestamp() + " " : "") + + (FconfSettings.ENABLE_TIMESTAMPS ? getTimestamp() + " " : "") + Player.getCurrentServer().hostname + " ~]> " + command ); @@ -646,11 +647,6 @@ let Terminal = { } }, - getTimestamp: function() { - const d = new Date(); - return `${d.getMonth() + 1}/${d.getDate()} ${`0${d.getHours()}`.slice(-2)}:${`0${d.getMinutes()}`.slice(-2)}`; - }, - finishAction: function(cancelled = false) { if (Terminal.hackFlag) { Terminal.finishHack(cancelled); diff --git a/utils/helpers/getTimestamp.ts b/utils/helpers/getTimestamp.ts new file mode 100644 index 000000000..fd0786166 --- /dev/null +++ b/utils/helpers/getTimestamp.ts @@ -0,0 +1,9 @@ +export function getTimestamp() { + const d: Date = new Date(); + // A negative slice value takes from the end of the string rather than the beginning. + const stringWidth: number = -2; + const formattedHours: string = `0${d.getHours()}`.slice(stringWidth); + const formattedMinutes: string = `0${d.getMinutes()}`.slice(stringWidth); + + return `${d.getMonth() + 1}/${d.getDate()} ${formattedHours}:${formattedMinutes}`; +}