blob: e963cb908609b4d7c8975ad7f70d94505271d14b [file] [log] [blame]
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'formattedTimestamp'
})
export class FormattedTimestampPipe implements PipeTransform {
transform(value: any, format: string = ''): string {
// Try and parse the passed value.
const momentDate = moment(value);
if ( value === '' ) {
return '';
}
if ( value === 'xxx') {
return null;
}
if ( value === null ) {
return '';
}
if ( value === undefined ) {
return '';
}
// If moment didn't understand the value, return it unformatted.
if (!momentDate.isValid()) {
return value;
}
// Otherwise, return the date formatted as requested.
return momentDate.format(format);
}
}