diff options
author | Alex <alexta69@gmail.com> | 2019-11-29 19:31:34 +0200 |
---|---|---|
committer | Alex <alexta69@gmail.com> | 2019-11-29 19:31:34 +0200 |
commit | 511404d23f5edd6ccf79db1fc1b0ba622134db24 (patch) | |
tree | 345fe66b840cd6496e1d4a7361a6b309519cad55 /ui/src/app/downloads.pipe.ts | |
download | metube-511404d23f5edd6ccf79db1fc1b0ba622134db24.tar.gz metube-511404d23f5edd6ccf79db1fc1b0ba622134db24.tar.bz2 metube-511404d23f5edd6ccf79db1fc1b0ba622134db24.zip |
initial commit: working version
Diffstat (limited to 'ui/src/app/downloads.pipe.ts')
-rw-r--r-- | ui/src/app/downloads.pipe.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ui/src/app/downloads.pipe.ts b/ui/src/app/downloads.pipe.ts new file mode 100644 index 0000000..d4a1654 --- /dev/null +++ b/ui/src/app/downloads.pipe.ts @@ -0,0 +1,37 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'eta' +}) +export class EtaPipe implements PipeTransform { + transform(value: number, ...args: any[]): any { + if (value === null) { + return null; + } + if (value < 60) { + return `${value}s`; + } + if (value < 3600) { + return `${Math.floor(value/60)}m ${value%60}s`; + } + const hours = Math.floor(value/3600) + const minutes = value % 3600 + return `${hours}h ${Math.floor(minutes/60)}m ${minutes%60}s`; + } +} + +@Pipe({ + name: 'speed' +}) +export class SpeedPipe implements PipeTransform { + transform(value: number, ...args: any[]): any { + if (value === null) { + return null; + } + const k = 1024; + const dm = 2; + const sizes = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s', 'PB/s', 'EB/s', 'ZB/s', 'YB/s']; + const i = Math.floor(Math.log(value) / Math.log(k)); + return parseFloat((value / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + } +} |