diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-01-07 14:38:01 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-01-07 14:47:50 +0100 |
commit | df8340b7b8daf108557309a3eaf97d495dbd2eab (patch) | |
tree | faa9d15081561f1ca2192fb86d3a4729a53e51ee /client/src/app/shared/angular | |
parent | 31174a272a65c83c8d3e10e9d5d59786bd05682a (diff) | |
download | PeerTube-df8340b7b8daf108557309a3eaf97d495dbd2eab.tar.gz PeerTube-df8340b7b8daf108557309a3eaf97d495dbd2eab.tar.zst PeerTube-df8340b7b8daf108557309a3eaf97d495dbd2eab.zip |
Add duration to video attributes in watch view
Diffstat (limited to 'client/src/app/shared/angular')
-rw-r--r-- | client/src/app/shared/angular/video-duration-formatter.pipe.ts | 19 |
1 files changed, 19 insertions, 0 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 new file mode 100644 index 000000000..c92631a75 --- /dev/null +++ b/client/src/app/shared/angular/video-duration-formatter.pipe.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import { Pipe, PipeTransform } from '@angular/core' | ||
2 | |||
3 | // Thanks: https://stackoverflow.com/a/46055604 | ||
4 | |||
5 | @Pipe({ | ||
6 | name: 'myVideoDurationFormatter' | ||
7 | }) | ||
8 | export class VideoDurationPipe implements PipeTransform { | ||
9 | transform (value: number): string { | ||
10 | const minutes = Math.floor(value / 60) | ||
11 | const hours = Math.floor(minutes / 60) | ||
12 | |||
13 | if (hours > 0) { | ||
14 | return hours + ' h ' + (minutes - hours * 60) + ' min ' + (value - (minutes - hours * 60) * 60) + ' sec' | ||
15 | } | ||
16 | |||
17 | return minutes + ' min ' + (value - minutes * 60) + ' sec' | ||
18 | } | ||
19 | } | ||