[TOSQUASH] pipe

This commit is contained in:
2017-05-14 01:24:32 +02:00
parent fb092f3b9b
commit 28641848e5

View 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);
}
}