aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/angular/video-duration-formatter.pipe.ts
blob: c92631a7540171ec21f0e595b1479aef04fe3c50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { Pipe, PipeTransform } from '@angular/core'

// Thanks: https://stackoverflow.com/a/46055604

@Pipe({
  name: 'myVideoDurationFormatter'
})
export class VideoDurationPipe implements PipeTransform {
  transform (value: number): string {
    const minutes = Math.floor(value / 60)
    const hours = Math.floor(minutes / 60)

    if (hours > 0) {
      return hours + ' h ' + (minutes - hours * 60) + ' min ' + (value - (minutes - hours * 60) * 60) + ' sec'
    }

    return minutes + ' min ' + (value - minutes * 60) + ' sec'
  }
}