aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/angular
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/angular')
-rw-r--r--client/src/app/shared/angular/video-duration-formatter.pipe.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/client/src/app/shared/angular/video-duration-formatter.pipe.ts b/client/src/app/shared/angular/video-duration-formatter.pipe.ts
new file mode 100644
index 000000000..c92631a75
--- /dev/null
+++ b/client/src/app/shared/angular/video-duration-formatter.pipe.ts
@@ -0,0 +1,19 @@
1import { Pipe, PipeTransform } from '@angular/core'
2
3// Thanks: https://stackoverflow.com/a/46055604
4
5@Pipe({
6 name: 'myVideoDurationFormatter'
7})
8export 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}