aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-10 10:26:20 +0200
committerChocobozzz <me@florianbigard.com>2022-08-10 10:26:20 +0200
commitf228e9f064f27301e59533aac48fd6c2e533890d (patch)
treee6c650382f5663d41bdf8606224cd0029f19fa47 /client/src/app/helpers
parent2a491182e483b97afb1b65c908b23cb48d591807 (diff)
downloadPeerTube-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.ts29
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 @@
1import { DatePipe } from '@angular/common' 1import { DatePipe } from '@angular/common'
2 2
3const datePipe = new DatePipe('en') 3let datePipe: DatePipe
4function dateToHuman (date: string) { 4let intl: Intl.DateTimeFormat
5 return datePipe.transform(date, 'medium') 5
6type DateFormat = 'medium' | 'precise'
7
8function 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
8function durationToString (duration: number) { 29function durationToString (duration: number) {
@@ -20,6 +41,8 @@ function durationToString (duration: number) {
20} 41}
21 42
22export { 43export {
44 DateFormat,
45
23 durationToString, 46 durationToString,
24 dateToHuman 47 dateToHuman
25} 48}