Skip to content

Commit

Permalink
fix(common): DatePipe doesn't throw for NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
DzmitryShylovich committed Jan 26, 2017
1 parent 1e729d7 commit 9a23b40
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/@angular/common/src/pipes/date_pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions modules/@angular/common/test/pipes/date_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });

Expand Down

0 comments on commit 9a23b40

Please sign in to comment.