import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class UtilService { constructor() { } format(value: number, type: string) { if (type == "time"){ return this.formatMs(value); } else { return ""+value; } } formatMs(valueInMs: number):string { const ms = Math.floor(valueInMs % 1000); const s = Math.floor((valueInMs / 1000) % 60); const m = Math.floor((valueInMs / (60*1000)) % 60); const h = Math.floor(valueInMs / (3600*1000)); var result = ""; if (h != 0) { result += h+"h "; } if (h!= 0 || m != 0) { result += m+"m "; } if (h!= 0 || m != 0 || s != 0) { result += s+"s "; result += ms+"ms"; } else { result += ms+"ms"; } return result; } toPercent(percentage: number) : string{ return (Math.round(percentage * 10000) / 100)+"%"; } }