]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/angular/video-duration-formatter.pipe.ts
Add duration to video attributes in watch view
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / angular / video-duration-formatter.pipe.ts
CommitLineData
df8340b7
RK
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}