Formatted time in netscript hgw display in human time, milliFormat now displays milli sometimes

This commit is contained in:
Olivier Gagnon
2021-05-02 01:04:49 -04:00
parent 56ce83cce5
commit 5a45e3584d
5 changed files with 28 additions and 9 deletions
+9 -2
View File
@@ -13,7 +13,8 @@ Converts a date representing time in milliseconds to a string with the format H
e.g. 10000 -> "10 seconds"
120000 -> "2 minutes and 0 seconds"
*/
function convertTimeMsToTimeElapsedString(time: number): string {
function convertTimeMsToTimeElapsedString(time: number, showMilli=false): string {
time = Math.floor(time);
const millisecondsPerSecond = 1000;
const secondPerMinute = 60;
const minutesPerHours = 60;
@@ -33,7 +34,13 @@ function convertTimeMsToTimeElapsedString(time: number): string {
const minutes: number = Math.floor(secTruncHours / secondPerMinute);
const secTruncMinutes: number = secTruncHours % secondPerMinute;
const seconds: number = secTruncMinutes;
const milliTruncSec: string = (() => {
let str: string = `${time % millisecondsPerSecond}`;
while(str.length < 3) str = "0"+str;
return str;
})()
const seconds: string = showMilli ? `${secTruncMinutes}.${milliTruncSec}` : `${secTruncMinutes}`;
let res = "";
if (days > 0) {res += `${days} days `; }