You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
649 B
TypeScript
31 lines
649 B
TypeScript
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
@Pipe({
|
|
name: 'ifDate'
|
|
})
|
|
export class IfDatePipe implements PipeTransform {
|
|
|
|
transform(value: any, args?: any): any {
|
|
if (value) {
|
|
if (typeof value === 'string') {
|
|
return this.evaluteDate(value);
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public evaluteDate(str: string): string {
|
|
const isDate = str.substring(1, 5);
|
|
if (isDate && (isDate.toLocaleLowerCase() === 'date')) {
|
|
const utc = parseInt(str.substring(6, str.length - 2), 10);
|
|
const appoDate = new Date(utc);
|
|
return appoDate.toLocaleDateString();
|
|
|
|
} else {
|
|
return str;
|
|
}
|
|
}
|
|
|
|
|
|
}
|