fix negative time display (#153)

This commit is contained in:
Snarling 2022-10-24 20:09:10 -04:00 committed by GitHub
parent df70458e4f
commit d7193ca8ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

@ -1737,9 +1737,7 @@ const base: InternalAPI<NS> = {
return numeralWrapper.format(n, format);
},
tFormat:
(ctx) =>
(_milliseconds, _milliPrecision = false) => {
tFormat: (ctx) => (_milliseconds, _milliPrecision) => {
const milliseconds = helpers.number(ctx, "milliseconds", _milliseconds);
const milliPrecision = !!_milliPrecision;
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);

@ -7,7 +7,8 @@ e.g. 10000 -> "10 seconds"
120000 -> "2 minutes and 0 seconds"
*/
function convertTimeMsToTimeElapsedString(time: number, showMilli = false): string {
time = Math.floor(time);
const negFlag = time < 0;
time = Math.abs(Math.floor(time));
const millisecondsPerSecond = 1000;
const secondPerMinute = 60;
const minutesPerHours = 60;
@ -47,7 +48,7 @@ function convertTimeMsToTimeElapsedString(time: number, showMilli = false): stri
}
res += `${seconds} second${!showMilli && secTruncMinutes === 1 ? "" : "s"}`;
return res;
return negFlag ? `-(${res})` : res;
}
// Finds the longest common starting substring in a set of strings