TOSQUASH I think I forgot this files previously...
This commit is contained in:
8
dashboard/src/app/convert-more-exact.pipe.spec.ts
Normal file
8
dashboard/src/app/convert-more-exact.pipe.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ConvertMoreExactPipe } from './convert-more-exact.pipe';
|
||||
|
||||
describe('ConvertMoreExactPipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new ConvertMoreExactPipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
||||
52
dashboard/src/app/convert-more-exact.pipe.ts
Normal file
52
dashboard/src/app/convert-more-exact.pipe.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'convertMoreExact'
|
||||
})
|
||||
export class ConvertMoreExactPipe implements PipeTransform {
|
||||
|
||||
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) {
|
||||
return '~' + (days + (hours > 12 ? 1 : 0)) + 'd';
|
||||
}
|
||||
if (hours > 0) {
|
||||
if (minutes > 45) {
|
||||
ret += (hours + 1) + 'h';
|
||||
} else if (minutes < 15) {
|
||||
ret += hours + 'h';
|
||||
} else {
|
||||
ret += hours + 'h 1/2';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if (minutes > 0) {
|
||||
ret += (minutes + (seconds > 35 ? 1 : 0)) + 'min';
|
||||
return ret;
|
||||
}
|
||||
if (seconds > 0) {
|
||||
if (seconds > 35) {
|
||||
return '~1min';
|
||||
} else {
|
||||
return seconds + 's';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user