diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-19 09:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:24:11 +0200 |
commit | dd24f1bb0a4b252e5342b251ba36853364da7b8e (patch) | |
tree | 41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/helpers/utils/date.ts | |
parent | 2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff) | |
download | PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip |
Add video filters to common video pages
Diffstat (limited to 'client/src/app/helpers/utils/date.ts')
-rw-r--r-- | client/src/app/helpers/utils/date.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/client/src/app/helpers/utils/date.ts b/client/src/app/helpers/utils/date.ts new file mode 100644 index 000000000..012b959ea --- /dev/null +++ b/client/src/app/helpers/utils/date.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { DatePipe } from '@angular/common' | ||
2 | |||
3 | const datePipe = new DatePipe('en') | ||
4 | function dateToHuman (date: string) { | ||
5 | return datePipe.transform(date, 'medium') | ||
6 | } | ||
7 | |||
8 | function durationToString (duration: number) { | ||
9 | const hours = Math.floor(duration / 3600) | ||
10 | const minutes = Math.floor((duration % 3600) / 60) | ||
11 | const seconds = duration % 60 | ||
12 | |||
13 | const minutesPadding = minutes >= 10 ? '' : '0' | ||
14 | const secondsPadding = seconds >= 10 ? '' : '0' | ||
15 | const displayedHours = hours > 0 ? hours.toString() + ':' : '' | ||
16 | |||
17 | return ( | ||
18 | displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() | ||
19 | ).replace(/^0/, '') | ||
20 | } | ||
21 | |||
22 | export { | ||
23 | durationToString, | ||
24 | dateToHuman | ||
25 | } | ||