From b5b687550d8ef8beafdf706e45d6556fb5f4c876 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Oct 2020 16:44:23 +0100 Subject: Add ability to save live replay --- .../shared-main/angular/duration-formatter.pipe.ts | 32 ++++++++++++++++++++++ client/src/app/shared/shared-main/angular/index.ts | 1 + 2 files changed, 33 insertions(+) create mode 100644 client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts (limited to 'client/src/app/shared/shared-main/angular') diff --git a/client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts b/client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts new file mode 100644 index 000000000..29ff864ec --- /dev/null +++ b/client/src/app/shared/shared-main/angular/duration-formatter.pipe.ts @@ -0,0 +1,32 @@ +import { Pipe, PipeTransform } from '@angular/core' + +@Pipe({ + name: 'myDurationFormatter' +}) +export class DurationFormatterPipe implements PipeTransform { + + transform (value: number): string { + const hours = Math.floor(value / 3600) + const minutes = Math.floor((value % 3600) / 60) + const seconds = value % 60 + + if (hours > 0) { + let result = $localize`${hours}h` + + if (minutes !== 0) result += ' ' + $localize`${minutes}min` + if (seconds !== 0) result += ' ' + $localize`${seconds}sec` + + return result + } + + if (minutes > 0) { + let result = $localize`${minutes}min` + + if (seconds !== 0) result += ' ' + `${seconds}sec` + + return result + } + + return $localize`${seconds} sec` + } +} diff --git a/client/src/app/shared/shared-main/angular/index.ts b/client/src/app/shared/shared-main/angular/index.ts index 9ba815136..29f8b3650 100644 --- a/client/src/app/shared/shared-main/angular/index.ts +++ b/client/src/app/shared/shared-main/angular/index.ts @@ -1,4 +1,5 @@ export * from './bytes.pipe' +export * from './duration-formatter.pipe' export * from './from-now.pipe' export * from './infinite-scroller.directive' export * from './number-formatter.pipe' -- cgit v1.2.3