aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/angular/video-duration-formatter.pipe.ts21
1 files changed, 15 insertions, 6 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
index c92631a75..4b6767415 100644
--- a/client/src/app/shared/angular/video-duration-formatter.pipe.ts
+++ b/client/src/app/shared/angular/video-duration-formatter.pipe.ts
@@ -1,19 +1,28 @@
1import { Pipe, PipeTransform } from '@angular/core' 1import { Pipe, PipeTransform } from '@angular/core'
2 2import { I18n } from '@ngx-translate/i18n-polyfill'
3// Thanks: https://stackoverflow.com/a/46055604
4 3
5@Pipe({ 4@Pipe({
6 name: 'myVideoDurationFormatter' 5 name: 'myVideoDurationFormatter'
7}) 6})
8export class VideoDurationPipe implements PipeTransform { 7export class VideoDurationPipe implements PipeTransform {
8
9 constructor (private i18n: I18n) {
10
11 }
12
9 transform (value: number): string { 13 transform (value: number): string {
10 const minutes = Math.floor(value / 60) 14 const hours = Math.floor(value / 3600)
11 const hours = Math.floor(minutes / 60) 15 const minutes = Math.floor((value % 3600) / 60)
16 const seconds = value % 60
12 17
13 if (hours > 0) { 18 if (hours > 0) {
14 return hours + ' h ' + (minutes - hours * 60) + ' min ' + (value - (minutes - hours * 60) * 60) + ' sec' 19 return this.i18n('{{hours}} h {{minutes}} min {{seconds}} sec', { hours, minutes, seconds })
20 }
21
22 if (minutes > 0) {
23 return this.i18n('{{minutes}} min {{seconds}} sec', { minutes, seconds })
15 } 24 }
16 25
17 return minutes + ' min ' + (value - minutes * 60) + ' sec' 26 return this.i18n('{{seconds}} sec', { seconds })
18 } 27 }
19} 28}