aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/+admin/system/jobs/job.service.ts4
-rw-r--r--client/src/app/+admin/system/jobs/jobs.component.html2
-rw-r--r--client/src/app/core/rest/rest-extractor.service.ts23
-rw-r--r--client/src/app/helpers/utils/date.ts29
4 files changed, 43 insertions, 15 deletions
diff --git a/client/src/app/+admin/system/jobs/job.service.ts b/client/src/app/+admin/system/jobs/job.service.ts
index 6c4a07469..ef8ddd3b4 100644
--- a/client/src/app/+admin/system/jobs/job.service.ts
+++ b/client/src/app/+admin/system/jobs/job.service.ts
@@ -34,9 +34,7 @@ export class JobService {
34 34
35 return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState || ''}`, { params }) 35 return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState || ''}`, { params })
36 .pipe( 36 .pipe(
37 map(res => { 37 map(res => this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ], 'precise')),
38 return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ])
39 }),
40 map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)), 38 map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)),
41 map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)), 39 map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)),
42 catchError(err => this.restExtractor.handleError(err)) 40 catchError(err => this.restExtractor.handleError(err))
diff --git a/client/src/app/+admin/system/jobs/jobs.component.html b/client/src/app/+admin/system/jobs/jobs.component.html
index b53fafeba..a5266bde5 100644
--- a/client/src/app/+admin/system/jobs/jobs.component.html
+++ b/client/src/app/+admin/system/jobs/jobs.component.html
@@ -69,7 +69,7 @@
69 <ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container> 69 <ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container>
70 </td> 70 </td>
71 71
72 <td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt | date: 'short' }}</td> 72 <td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt }}</td>
73 </tr> 73 </tr>
74 </ng-template> 74 </ng-template>
75 75
diff --git a/client/src/app/core/rest/rest-extractor.service.ts b/client/src/app/core/rest/rest-extractor.service.ts
index 8a2974563..7eec2eca6 100644
--- a/client/src/app/core/rest/rest-extractor.service.ts
+++ b/client/src/app/core/rest/rest-extractor.service.ts
@@ -1,14 +1,17 @@
1import { throwError as observableThrowError } from 'rxjs' 1import { throwError as observableThrowError } from 'rxjs'
2import { Injectable } from '@angular/core' 2import { Inject, Injectable, LOCALE_ID } from '@angular/core'
3import { Router } from '@angular/router' 3import { Router } from '@angular/router'
4import { dateToHuman } from '@app/helpers' 4import { DateFormat, dateToHuman } from '@app/helpers'
5import { HttpStatusCode, ResultList } from '@shared/models'
6import { logger } from '@root-helpers/logger' 5import { logger } from '@root-helpers/logger'
6import { HttpStatusCode, ResultList } from '@shared/models'
7 7
8@Injectable() 8@Injectable()
9export class RestExtractor { 9export class RestExtractor {
10 10
11 constructor (private router: Router) { } 11 constructor (
12 @Inject(LOCALE_ID) private localeId: string,
13 private router: Router
14 ) { }
12 15
13 applyToResultListData <T, A, U> ( 16 applyToResultListData <T, A, U> (
14 result: ResultList<T>, 17 result: ResultList<T>,
@@ -23,13 +26,17 @@ export class RestExtractor {
23 } 26 }
24 } 27 }
25 28
26 convertResultListDateToHuman <T> (result: ResultList<T>, fieldsToConvert: string[] = [ 'createdAt' ]): ResultList<T> { 29 convertResultListDateToHuman <T> (
27 return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ]) 30 result: ResultList<T>,
31 fieldsToConvert: string[] = [ 'createdAt' ],
32 format?: DateFormat
33 ): ResultList<T> {
34 return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert, format ])
28 } 35 }
29 36
30 convertDateToHuman (target: any, fieldsToConvert: string[]) { 37 convertDateToHuman (target: any, fieldsToConvert: string[], format?: DateFormat) {
31 fieldsToConvert.forEach(field => { 38 fieldsToConvert.forEach(field => {
32 target[field] = dateToHuman(target[field]) 39 target[field] = dateToHuman(this.localeId, new Date(target[field]), format)
33 }) 40 })
34 41
35 return target 42 return target
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}