diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-10 10:26:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-10 10:26:20 +0200 |
commit | f228e9f064f27301e59533aac48fd6c2e533890d (patch) | |
tree | e6c650382f5663d41bdf8606224cd0029f19fa47 /client/src/app/helpers | |
parent | 2a491182e483b97afb1b65c908b23cb48d591807 (diff) | |
download | PeerTube-f228e9f064f27301e59533aac48fd6c2e533890d.tar.gz PeerTube-f228e9f064f27301e59533aac48fd6c2e533890d.tar.zst PeerTube-f228e9f064f27301e59533aac48fd6c2e533890d.zip |
More precise date for jobs
Diffstat (limited to 'client/src/app/helpers')
-rw-r--r-- | client/src/app/helpers/utils/date.ts | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/client/src/app/helpers/utils/date.ts b/client/src/app/helpers/utils/date.ts index 012b959ea..75363cc81 100644 --- a/client/src/app/helpers/utils/date.ts +++ b/client/src/app/helpers/utils/date.ts | |||
@@ -1,8 +1,29 @@ | |||
1 | import { DatePipe } from '@angular/common' | 1 | import { DatePipe } from '@angular/common' |
2 | 2 | ||
3 | const datePipe = new DatePipe('en') | 3 | let datePipe: DatePipe |
4 | function dateToHuman (date: string) { | 4 | let intl: Intl.DateTimeFormat |
5 | return datePipe.transform(date, 'medium') | 5 | |
6 | type DateFormat = 'medium' | 'precise' | ||
7 | |||
8 | function dateToHuman (localeId: string, date: Date, format: 'medium' | 'precise' = 'medium') { | ||
9 | if (!datePipe) { | ||
10 | datePipe = new DatePipe(localeId) | ||
11 | } | ||
12 | |||
13 | if (!intl) { | ||
14 | intl = new Intl.DateTimeFormat(localeId, { | ||
15 | hour: 'numeric', | ||
16 | minute: 'numeric', | ||
17 | second: 'numeric', | ||
18 | year: '2-digit', | ||
19 | month: 'numeric', | ||
20 | day: 'numeric', | ||
21 | fractionalSecondDigits: 3 | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | if (format === 'medium') return datePipe.transform(date, format) | ||
26 | if (format === 'precise') return intl.format(date) | ||
6 | } | 27 | } |
7 | 28 | ||
8 | function durationToString (duration: number) { | 29 | function durationToString (duration: number) { |
@@ -20,6 +41,8 @@ function durationToString (duration: number) { | |||
20 | } | 41 | } |
21 | 42 | ||
22 | export { | 43 | export { |
44 | DateFormat, | ||
45 | |||
23 | durationToString, | 46 | durationToString, |
24 | dateToHuman | 47 | dateToHuman |
25 | } | 48 | } |