]>
Commit | Line | Data |
---|---|---|
df8340b7 RK |
1 | import { Pipe, PipeTransform } from '@angular/core' |
2 | ||
3 | // Thanks: https://stackoverflow.com/a/46055604 | |
4 | ||
5 | @Pipe({ | |
6 | name: 'myVideoDurationFormatter' | |
7 | }) | |
8 | export class VideoDurationPipe implements PipeTransform { | |
9 | transform (value: number): string { | |
10 | const minutes = Math.floor(value / 60) | |
11 | const hours = Math.floor(minutes / 60) | |
12 | ||
13 | if (hours > 0) { | |
14 | return hours + ' h ' + (minutes - hours * 60) + ' min ' + (value - (minutes - hours * 60) * 60) + ' sec' | |
15 | } | |
16 | ||
17 | return minutes + ' min ' + (value - minutes * 60) + ' sec' | |
18 | } | |
19 | } |