2016-04-27 11:28:22 -07:00
|
|
|
import {Injectable, Pipe} from '@angular/core';
|
|
|
|
import {DatePipe} from '@angular/common';
|
2016-01-27 14:49:02 -08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
// #docregion date-pipe
|
|
|
|
@Pipe({name: 'date', pure: true})
|
|
|
|
export class StringSafeDatePipe extends DatePipe {
|
2016-04-27 11:28:22 -07:00
|
|
|
transform(value: any, format: string): string {
|
2016-01-27 14:49:02 -08:00
|
|
|
value = typeof value === 'string' ?
|
2016-04-27 11:28:22 -07:00
|
|
|
Date.parse(value) : value;
|
|
|
|
return super.transform(value, format);
|
2016-01-27 14:49:02 -08:00
|
|
|
}
|
|
|
|
}
|
2016-02-24 23:28:45 -08:00
|
|
|
// #enddocregion date-pipe
|