From 03db5c3f979928419fb3ead8c65f0bce12d07f5c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Mar 2020 15:46:48 +0100 Subject: Correctly format video duration --- .../shared/angular/video-duration-formatter.pipe.ts | 21 +++++++++++++++------ 1 file 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 @@ import { Pipe, PipeTransform } from '@angular/core' - -// Thanks: https://stackoverflow.com/a/46055604 +import { I18n } from '@ngx-translate/i18n-polyfill' @Pipe({ name: 'myVideoDurationFormatter' }) export class VideoDurationPipe implements PipeTransform { + + constructor (private i18n: I18n) { + + } + transform (value: number): string { - const minutes = Math.floor(value / 60) - const hours = Math.floor(minutes / 60) + const hours = Math.floor(value / 3600) + const minutes = Math.floor((value % 3600) / 60) + const seconds = value % 60 if (hours > 0) { - return hours + ' h ' + (minutes - hours * 60) + ' min ' + (value - (minutes - hours * 60) * 60) + ' sec' + return this.i18n('{{hours}} h {{minutes}} min {{seconds}} sec', { hours, minutes, seconds }) + } + + if (minutes > 0) { + return this.i18n('{{minutes}} min {{seconds}} sec', { minutes, seconds }) } - return minutes + ' min ' + (value - minutes * 60) + ' sec' + return this.i18n('{{seconds}} sec', { seconds }) } } -- cgit v1.2.3