From 7ad616a177ba297699afa11fd8b31266fe27b29a Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Thu, 26 Jan 2017 18:23:53 +0300 Subject: [PATCH] fix(common): DatePipe doesn't throw for NaN (#14117) Fixes #14103 PR Close #14117 --- modules/@angular/common/src/pipes/date_pipe.ts | 2 +- modules/@angular/common/test/pipes/date_pipe_spec.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/@angular/common/src/pipes/date_pipe.ts b/modules/@angular/common/src/pipes/date_pipe.ts index ef32b3b013..872cef2975 100644 --- a/modules/@angular/common/src/pipes/date_pipe.ts +++ b/modules/@angular/common/src/pipes/date_pipe.ts @@ -103,7 +103,7 @@ export class DatePipe implements PipeTransform { transform(value: any, pattern: string = 'mediumDate'): string { let date: Date; - if (isBlank(value)) return null; + if (isBlank(value) || value !== value) return null; if (typeof value === 'string') { value = value.trim(); diff --git a/modules/@angular/common/test/pipes/date_pipe_spec.ts b/modules/@angular/common/test/pipes/date_pipe_spec.ts index a0eb9d9c43..1db44aa928 100644 --- a/modules/@angular/common/test/pipes/date_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/date_pipe_spec.ts @@ -53,6 +53,8 @@ export function main() { it('should return null for empty string', () => expect(pipe.transform('')).toEqual(null)); + it('should return null for NaN', () => expect(pipe.transform(Number.NaN)).toEqual(null)); + it('should support ISO string without time', () => { expect(() => pipe.transform(isoStringWithoutTime)).not.toThrow(); });