From c5cfe2b3936f3175a97c7ac3f4b5f47632f197f4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 19 Oct 2010 20:38:49 -0700 Subject: fix date filter to igrone falsy input --- src/filters.js | 2 +- test/FiltersSpec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/filters.js b/src/filters.js index 7e0f2b42..5b734882 100644 --- a/src/filters.js +++ b/src/filters.js @@ -75,7 +75,7 @@ var DATE_FORMATS = { var DATE_FORMATS_SPLIT = /([^yMdHhmsaZ]*)(y+|M+|d+|H+|h+|m+|s+|a|Z)(.*)/; angularFilter.date = function(date, format) { - if (!date instanceof Date) return date; + if (!(date instanceof Date)) return date; var text = date.toLocaleDateString(), fn; if (format && isString(format)) { text = ''; diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js index 3e5ca9a6..fbaceac6 100644 --- a/test/FiltersSpec.js +++ b/test/FiltersSpec.js @@ -100,6 +100,12 @@ describe('filter', function(){ midnight.getTimezoneOffset = function() { return 7 * 60; }; + it('should ignore falsy inputs', function() { + expect(filter.date(null)).toEqual(null); + expect(filter.date('')).toEqual(''); + expect(filter.date(123)).toEqual(123); + }); + it('should do basic filter', function() { expect(filter.date(noon)).toEqual(noon.toLocaleDateString()); expect(filter.date(noon, '')).toEqual(noon.toLocaleDateString()); -- cgit v1.2.3