mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 21:53:50 +01:00
[refactor] pulling getTimestamp off Terminal
This commit is contained in:
parent
0345daf359
commit
3130b410e2
@ -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;
|
||||
|
@ -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);
|
||||
|
9
utils/helpers/getTimestamp.ts
Normal file
9
utils/helpers/getTimestamp.ts
Normal file
@ -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}`;
|
||||
}
|
Loading…
Reference in New Issue
Block a user