More precise date for jobs
This commit is contained in:
parent
2a491182e4
commit
f228e9f064
|
@ -34,9 +34,7 @@ export class JobService {
|
|||
|
||||
return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState || ''}`, { params })
|
||||
.pipe(
|
||||
map(res => {
|
||||
return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ])
|
||||
}),
|
||||
map(res => this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ], 'precise')),
|
||||
map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)),
|
||||
map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)),
|
||||
catchError(err => this.restExtractor.handleError(err))
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
<ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container>
|
||||
</td>
|
||||
|
||||
<td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt | date: 'short' }}</td>
|
||||
<td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt }}</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
import { throwError as observableThrowError } from 'rxjs'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Inject, Injectable, LOCALE_ID } from '@angular/core'
|
||||
import { Router } from '@angular/router'
|
||||
import { dateToHuman } from '@app/helpers'
|
||||
import { HttpStatusCode, ResultList } from '@shared/models'
|
||||
import { DateFormat, dateToHuman } from '@app/helpers'
|
||||
import { logger } from '@root-helpers/logger'
|
||||
import { HttpStatusCode, ResultList } from '@shared/models'
|
||||
|
||||
@Injectable()
|
||||
export class RestExtractor {
|
||||
|
||||
constructor (private router: Router) { }
|
||||
constructor (
|
||||
@Inject(LOCALE_ID) private localeId: string,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
applyToResultListData <T, A, U> (
|
||||
result: ResultList<T>,
|
||||
|
@ -23,13 +26,17 @@ export class RestExtractor {
|
|||
}
|
||||
}
|
||||
|
||||
convertResultListDateToHuman <T> (result: ResultList<T>, fieldsToConvert: string[] = [ 'createdAt' ]): ResultList<T> {
|
||||
return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ])
|
||||
convertResultListDateToHuman <T> (
|
||||
result: ResultList<T>,
|
||||
fieldsToConvert: string[] = [ 'createdAt' ],
|
||||
format?: DateFormat
|
||||
): ResultList<T> {
|
||||
return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert, format ])
|
||||
}
|
||||
|
||||
convertDateToHuman (target: any, fieldsToConvert: string[]) {
|
||||
convertDateToHuman (target: any, fieldsToConvert: string[], format?: DateFormat) {
|
||||
fieldsToConvert.forEach(field => {
|
||||
target[field] = dateToHuman(target[field])
|
||||
target[field] = dateToHuman(this.localeId, new Date(target[field]), format)
|
||||
})
|
||||
|
||||
return target
|
||||
|
|
|
@ -1,8 +1,29 @@
|
|||
import { DatePipe } from '@angular/common'
|
||||
|
||||
const datePipe = new DatePipe('en')
|
||||
function dateToHuman (date: string) {
|
||||
return datePipe.transform(date, 'medium')
|
||||
let datePipe: DatePipe
|
||||
let intl: Intl.DateTimeFormat
|
||||
|
||||
type DateFormat = 'medium' | 'precise'
|
||||
|
||||
function dateToHuman (localeId: string, date: Date, format: 'medium' | 'precise' = 'medium') {
|
||||
if (!datePipe) {
|
||||
datePipe = new DatePipe(localeId)
|
||||
}
|
||||
|
||||
if (!intl) {
|
||||
intl = new Intl.DateTimeFormat(localeId, {
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
second: 'numeric',
|
||||
year: '2-digit',
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
fractionalSecondDigits: 3
|
||||
})
|
||||
}
|
||||
|
||||
if (format === 'medium') return datePipe.transform(date, format)
|
||||
if (format === 'precise') return intl.format(date)
|
||||
}
|
||||
|
||||
function durationToString (duration: number) {
|
||||
|
@ -20,6 +41,8 @@ function durationToString (duration: number) {
|
|||
}
|
||||
|
||||
export {
|
||||
DateFormat,
|
||||
|
||||
durationToString,
|
||||
dateToHuman
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"node_modules/@types"
|
||||
],
|
||||
"lib": [
|
||||
"ES2020.Intl",
|
||||
"ES2021.Intl",
|
||||
"es2018",
|
||||
"es2017",
|
||||
"es2016",
|
||||
|
|
Loading…
Reference in New Issue