(front) Fix pipe to convert ms to day/hour/min/sec
This commit is contained in:
@@ -12,18 +12,18 @@ export class ConvertMoreExactPipe implements PipeTransform {
|
||||
transform(timeMs: number): string {
|
||||
let x = timeMs / 1000;
|
||||
|
||||
const seconds = Math.round(x % 60);
|
||||
const seconds = Math.floor(x % 60);
|
||||
x /= 60;
|
||||
|
||||
let minutes = 0;
|
||||
if (x > 1) { minutes = Math.round(x % 60); }
|
||||
if (x > 1) { minutes = Math.floor(x % 60); }
|
||||
x /= 60;
|
||||
|
||||
let hours = 0;
|
||||
if (x > 1) { hours = Math.round(x % 24); }
|
||||
if (x > 1) { hours = Math.floor(x % 24); }
|
||||
// TODO Enable/disable day
|
||||
x /= 24;
|
||||
const days = Math.round(x);
|
||||
const days = Math.floor(x);
|
||||
|
||||
// Final string
|
||||
let ret = '~';
|
||||
|
||||
@@ -12,22 +12,22 @@ export class ConvertMsPipe implements PipeTransform {
|
||||
transform(timeMs: number): string {
|
||||
let x = timeMs / 1000;
|
||||
|
||||
const seconds = Math.round(x % 60);
|
||||
const seconds = Math.floor(x % 60);
|
||||
x /= 60;
|
||||
|
||||
let minutes = 0;
|
||||
if (x > 1) { minutes = Math.round(x % 60); }
|
||||
if (x > 1) { minutes = Math.floor(x % 60); }
|
||||
x /= 60;
|
||||
|
||||
let hours = 0;
|
||||
if (x > 1) { hours = Math.round(x % 24); }
|
||||
if (x > 1) { hours = Math.floor(x % 24); }
|
||||
// TODO Enable/disable day
|
||||
x /= 24;
|
||||
const days = Math.round(x);
|
||||
const days = Math.floor(x);
|
||||
|
||||
// Final string
|
||||
let ret = '';
|
||||
if (days > 0) { ret += ('0' + days).slice(-2) + 'd'; }
|
||||
if (days > 0) { ret += parseInt('0' + days) + 'd'; }
|
||||
if (hours > 0) { ret += ('0' + hours).slice(-2) + 'h'; }
|
||||
if (minutes > 0) { ret += ('0' + minutes).slice(-2) + 'm'; }
|
||||
if (seconds > 0) { ret += ('0' + seconds).slice(-2) + 's'; }
|
||||
|
||||
Reference in New Issue
Block a user