Refactoring
Move Top Played part. Move pipes and dashboard Rename object folder to model Doc pipes
This commit is contained in:
38
dashboard/src/app/pipes/convertms.pipe.ts
Normal file
38
dashboard/src/app/pipes/convertms.pipe.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'convertMs'
|
||||
})
|
||||
export class ConvertMsPipe implements PipeTransform {
|
||||
|
||||
/**
|
||||
* Convert milliseconds to "readable" duration e.g. 1d21h35m24s
|
||||
* @param timeMs time in milliseconds
|
||||
*/
|
||||
transform(timeMs: number): string {
|
||||
let x = timeMs / 1000;
|
||||
|
||||
const 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;
|
||||
const days = Math.round(x);
|
||||
|
||||
// Final string
|
||||
let ret = '';
|
||||
if (days > 0) { ret += ('0' + days).slice(-2) + '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'; }
|
||||
|
||||
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