aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-03-18 15:46:48 +0100
committerChocobozzz <me@florianbigard.com>2020-03-18 15:46:48 +0100
commit03db5c3f979928419fb3ead8c65f0bce12d07f5c (patch)
tree4c2c29c56c16c1eeb5a60681b279f2f8819a89f0 /client/src/app
parenta31bec51554261b1f67cdd4ebdb6afba4d8ee65a (diff)
downloadPeerTube-03db5c3f979928419fb3ead8c65f0bce12d07f5c.tar.gz
PeerTube-03db5c3f979928419fb3ead8c65f0bce12d07f5c.tar.zst
PeerTube-03db5c3f979928419fb3ead8c65f0bce12d07f5c.zip
Correctly format video duration
Diffstat (limited to 'client/src/app')
-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}