blob: 0b5bc89f2a20fc201980842916511adb3358a192 [file] [log] [blame]
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
/**
* Pipe to transform a string to a date
*/
@Pipe({name: 'stringToDate'})
export class StringToDatePipe implements PipeTransform {
/**
* Constructor
*/
constructor() {
}
/**
* Transform a date that is passed as string into a date
* @param value The date passed as string
* @returns {Date} The Date object
*/
transform(value: string, format: string = ''): Date {
if ( value === null || value === undefined || value === '' ) {
return null;
}
const ret = new Date(value);
if ( ret + '' === 'Invalid Date') {
return null;
} else {
return new Date( ret );
}
}
}