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 })
|
return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState || ''}`, { params })
|
||||||
.pipe(
|
.pipe(
|
||||||
map(res => {
|
map(res => this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ], 'precise')),
|
||||||
return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ])
|
|
||||||
}),
|
|
||||||
map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)),
|
map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)),
|
||||||
map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)),
|
map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)),
|
||||||
catchError(err => this.restExtractor.handleError(err))
|
catchError(err => this.restExtractor.handleError(err))
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
<ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container>
|
<ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container>
|
||||||
</td>
|
</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>
|
</tr>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
import { throwError as observableThrowError } from 'rxjs'
|
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 { Router } from '@angular/router'
|
||||||
import { dateToHuman } from '@app/helpers'
|
import { DateFormat, dateToHuman } from '@app/helpers'
|
||||||
import { HttpStatusCode, ResultList } from '@shared/models'
|
|
||||||
import { logger } from '@root-helpers/logger'
|
import { logger } from '@root-helpers/logger'
|
||||||
|
import { HttpStatusCode, ResultList } from '@shared/models'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RestExtractor {
|
export class RestExtractor {
|
||||||
|
|
||||||
constructor (private router: Router) { }
|
constructor (
|
||||||
|
@Inject(LOCALE_ID) private localeId: string,
|
||||||
|
private router: Router
|
||||||
|
) { }
|
||||||
|
|
||||||
applyToResultListData <T, A, U> (
|
applyToResultListData <T, A, U> (
|
||||||
result: ResultList<T>,
|
result: ResultList<T>,
|
||||||
|
@ -23,13 +26,17 @@ export class RestExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
convertResultListDateToHuman <T> (result: ResultList<T>, fieldsToConvert: string[] = [ 'createdAt' ]): ResultList<T> {
|
convertResultListDateToHuman <T> (
|
||||||
return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ])
|
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 => {
|
fieldsToConvert.forEach(field => {
|
||||||
target[field] = dateToHuman(target[field])
|
target[field] = dateToHuman(this.localeId, new Date(target[field]), format)
|
||||||
})
|
})
|
||||||
|
|
||||||
return target
|
return target
|
||||||
|
|
|
@ -1,8 +1,29 @@
|
||||||
import { DatePipe } from '@angular/common'
|
import { DatePipe } from '@angular/common'
|
||||||
|
|
||||||
const datePipe = new DatePipe('en')
|
let datePipe: DatePipe
|
||||||
function dateToHuman (date: string) {
|
let intl: Intl.DateTimeFormat
|
||||||
return datePipe.transform(date, 'medium')
|
|
||||||
|
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) {
|
function durationToString (duration: number) {
|
||||||
|
@ -20,6 +41,8 @@ function durationToString (duration: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
DateFormat,
|
||||||
|
|
||||||
durationToString,
|
durationToString,
|
||||||
dateToHuman
|
dateToHuman
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
"node_modules/@types"
|
"node_modules/@types"
|
||||||
],
|
],
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2020.Intl",
|
"ES2021.Intl",
|
||||||
"es2018",
|
"es2018",
|
||||||
"es2017",
|
"es2017",
|
||||||
"es2016",
|
"es2016",
|
||||||
|
|
Loading…
Reference in New Issue