]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-watch/video-duration-formatter.pipe.ts
Reorganize client shared modules
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / video-duration-formatter.pipe.ts
1 import { Pipe, PipeTransform } from '@angular/core'
2 import { I18n } from '@ngx-translate/i18n-polyfill'
3
4 @Pipe({
5 name: 'myVideoDurationFormatter'
6 })
7 export class VideoDurationPipe implements PipeTransform {
8
9 constructor (private i18n: I18n) {
10
11 }
12
13 transform (value: number): string {
14 const hours = Math.floor(value / 3600)
15 const minutes = Math.floor((value % 3600) / 60)
16 const seconds = value % 60
17
18 if (hours > 0) {
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 })
24 }
25
26 return this.i18n('{{seconds}} sec', { seconds })
27 }
28 }