From df8340b7b8daf108557309a3eaf97d495dbd2eab Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 7 Jan 2020 14:38:01 +0100 Subject: Add duration to video attributes in watch view --- .../shared/angular/video-duration-formatter.pipe.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 client/src/app/shared/angular/video-duration-formatter.pipe.ts (limited to 'client/src/app/shared/angular') diff --git a/client/src/app/shared/angular/video-duration-formatter.pipe.ts b/client/src/app/shared/angular/video-duration-formatter.pipe.ts new file mode 100644 index 000000000..c92631a75 --- /dev/null +++ b/client/src/app/shared/angular/video-duration-formatter.pipe.ts @@ -0,0 +1,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' + } +} -- cgit v1.2.3