[TOSQUASH] pipe
This commit is contained in:
31
dashboard/src/app/convertms.pipe.ts
Normal file
31
dashboard/src/app/convertms.pipe.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({name: "convertMs"})
|
||||
export class ConvertMsPipe implements PipeTransform {
|
||||
transform(timeMs: number): string {
|
||||
let x = timeMs / 1000
|
||||
|
||||
let seconds = Math.round(x % 60)
|
||||
x /= 60
|
||||
|
||||
let minutes = 0
|
||||
if (x > 1) minutes = Math.round(x % 60)
|
||||
x /= 60
|
||||
|
||||
let hours = 0
|
||||
if (x > 1) hours = Math.round(x % 24)
|
||||
// TODO Enable/disable day
|
||||
x /= 24
|
||||
let days = Math.round(x);
|
||||
|
||||
// Final string
|
||||
let ret = "";
|
||||
if (days > 0) ret += ('0' + days).slice(-2) + ":";
|
||||
if (hours > 0) ret += ('0' + hours).slice(-2) + ":";
|
||||
if (minutes > 0) ret += ('0' + minutes).slice(-2) + ":";
|
||||
if (seconds > 0) ret += ('0' + seconds).slice(-2);
|
||||
|
||||
return ret;
|
||||
// return ('0' + days).slice(-2) + ":" + ('0' + hours).slice(-2) + ":" + ('0' + minutes).slice(-2) + ":" + ('0' + seconds).slice(-2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user