From c76110b575e3f4070c7b2ef66fb39f7b09b0e244 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Fri, 12 Mar 2021 14:32:07 -0500 Subject: [PATCH] added tFormat to represent times. --- doc/source/netscript/basicfunctions/tFormat.rst | 15 +++++++++++++++ src/Constants.ts | 2 ++ src/NetscriptFunctions.js | 4 ++++ src/index.html | 6 +++--- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 doc/source/netscript/basicfunctions/tFormat.rst diff --git a/doc/source/netscript/basicfunctions/tFormat.rst b/doc/source/netscript/basicfunctions/tFormat.rst new file mode 100644 index 000000000..e2acd5cef --- /dev/null +++ b/doc/source/netscript/basicfunctions/tFormat.rst @@ -0,0 +1,15 @@ +tFormat() Netscript Function +============================ + +.. js:function:: tFormat(milliseconds) + + :RAM cost: 0 GB + :param number milliseconds: Amount of milliseconds to format. + :returns: milliseconds in the "D M H S" format + + Example: + + .. code-block:: javascript + + tFormat(3000); // returns: "3 seconds" + tFormat(10000000); // returns: "2 hours 46 minutes 40 seconds" diff --git a/src/Constants.ts b/src/Constants.ts index 76751c02e..9cddaa04b 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -236,6 +236,8 @@ export let CONSTANTS: IMap = { Netscript * Ace editor will now correctly highlight all functions. + * 'tFormat' is a new netscript function that returns a human readable + representation of milliseconds. eg. "2 hours 15 minute 43 seconds" Gang * style improvements diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 4ec58a351..c833a6bfa 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -151,6 +151,7 @@ import { numeralWrapper } from "./ui/numeralFormat"; import { post } from "./ui/postToTerminal"; import { setTimeoutRef } from "./utils/SetTimeoutRef"; import { is2DArray } from "./utils/helpers/is2DArray"; +import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions"; import { dialogBoxCreate } from "../utils/DialogBox"; import { formatNumber, isHTML } from "../utils/StringHelperFunctions"; @@ -2349,6 +2350,9 @@ function NetscriptFunctions(workerScript) { return numeralWrapper.format(parseFloat(n), format); }, + tFormat: function(milliseconds) { + return convertTimeMsToTimeElapsedString(milliseconds); + }, getTimeSinceLastAug: function() { updateDynamicRam("getTimeSinceLastAug", getRamCost("getTimeSinceLastAug")); return Player.playtimeSinceLastAug; diff --git a/src/index.html b/src/index.html index fb7af1c5c..d6858f0ad 100644 --- a/src/index.html +++ b/src/index.html @@ -153,17 +153,17 @@ if (htmlWebpackPlugin.options.googleAnalytics.trackingId) { %>
- +
- +
- +