mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-02 16:49:48 +01:00
Handle invalid date for HarborDatePipe (#15359)
Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
f6801cea57
commit
538266c51a
@ -109,7 +109,7 @@
|
||||
<clr-dg-cell>{{t.operation}}</clr-dg-cell>
|
||||
<clr-dg-cell>{{getStatusStr(t.status)}}</clr-dg-cell>
|
||||
<clr-dg-cell>{{t.start_time | harborDatetime: 'short'}}</clr-dg-cell>
|
||||
<clr-dg-cell>{{t.end_time && t.end_time != '0001-01-01T00:00:00Z' ? (t.end_time | harborDatetime: 'short') : "-"}}</clr-dg-cell>
|
||||
<clr-dg-cell>{{t.end_time | harborDatetime: 'short'}}</clr-dg-cell>
|
||||
<clr-dg-cell>
|
||||
<a target="_blank" [href]="viewLog(t.id)" *ngIf="t.status !== 'Initialized'">
|
||||
<clr-icon shape="list"></clr-icon>
|
||||
|
@ -2,18 +2,23 @@ import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { DatePipe } from "@angular/common";
|
||||
import { DEFAULT_LANG_LOCALSTORAGE_KEY, DeFaultLang } from "../entities/shared.const";
|
||||
|
||||
const baseTimeLine: Date = new Date('1970-1-1');
|
||||
|
||||
@Pipe({
|
||||
name: 'harborDatetime',
|
||||
pure: false
|
||||
name: 'harborDatetime',
|
||||
pure: false
|
||||
})
|
||||
export class HarborDatetimePipe implements PipeTransform {
|
||||
|
||||
transform(value: any, format?: string): string {
|
||||
let lang: string = DeFaultLang;
|
||||
if (localStorage && localStorage.getItem(DEFAULT_LANG_LOCALSTORAGE_KEY)) {
|
||||
lang = localStorage.getItem(DEFAULT_LANG_LOCALSTORAGE_KEY);
|
||||
transform(value: any, format?: string): string {
|
||||
let lang: string = DeFaultLang;
|
||||
if (localStorage && localStorage.getItem(DEFAULT_LANG_LOCALSTORAGE_KEY)) {
|
||||
lang = localStorage.getItem(DEFAULT_LANG_LOCALSTORAGE_KEY);
|
||||
}
|
||||
if (value && value <= baseTimeLine) {// invalid date
|
||||
return '-';
|
||||
}
|
||||
// default format medium
|
||||
return new DatePipe(lang).transform(value, format ? format : 'medium');
|
||||
}
|
||||
// default format medium
|
||||
return new DatePipe(lang).transform(value, format ? format : 'medium');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user