]>
Commit | Line | Data |
---|---|---|
b5b68755 C |
1 | import { Pipe, PipeTransform } from '@angular/core' |
2 | ||
3 | @Pipe({ | |
4 | name: 'myDurationFormatter' | |
5 | }) | |
6 | export class DurationFormatterPipe implements PipeTransform { | |
7 | ||
8 | transform (value: number): string { | |
9 | const hours = Math.floor(value / 3600) | |
10 | const minutes = Math.floor((value % 3600) / 60) | |
11 | const seconds = value % 60 | |
12 | ||
13 | if (hours > 0) { | |
14 | let result = $localize`${hours}h` | |
15 | ||
16 | if (minutes !== 0) result += ' ' + $localize`${minutes}min` | |
17 | if (seconds !== 0) result += ' ' + $localize`${seconds}sec` | |
18 | ||
19 | return result | |
20 | } | |
21 | ||
22 | if (minutes > 0) { | |
23 | let result = $localize`${minutes}min` | |
24 | ||
25 | if (seconds !== 0) result += ' ' + `${seconds}sec` | |
26 | ||
27 | return result | |
28 | } | |
29 | ||
30 | return $localize`${seconds} sec` | |
31 | } | |
32 | } |