diff options
| author | Misko Hevery | 2010-10-23 14:37:44 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-10-23 14:38:08 -0700 | 
| commit | 1391f19fb49275af59230afef51b472c58d7818c (patch) | |
| tree | bb960cf6464262e34087af229aa47fa496047378 | |
| parent | 04a4d8b061d98f46dc97fb550d388d248845b369 (diff) | |
| download | angular.js-1391f19fb49275af59230afef51b472c58d7818c.tar.bz2 | |
added support for treating numbers as date in miliseconds
| -rw-r--r-- | src/filters.js | 10 | ||||
| -rw-r--r-- | test/FiltersSpec.js | 4 | 
2 files changed, 11 insertions, 3 deletions
diff --git a/src/filters.js b/src/filters.js index 5b734882..7db5403c 100644 --- a/src/filters.js +++ b/src/filters.js @@ -75,8 +75,14 @@ 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; -  var text = date.toLocaleDateString(), fn; +  var text, fn; +  if (!date) return date; +  if (!(date instanceof Date)) { +    text = parseInt(date, 10); +    date = new Date(); +    date.setTime(text); +  } +  text = date.toLocaleDateString();    if (format && isString(format)) {      text = '';      var parts = []; diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js index fbaceac6..0c4afbbd 100644 --- a/test/FiltersSpec.js +++ b/test/FiltersSpec.js @@ -103,7 +103,6 @@ describe('filter', function(){      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() { @@ -123,6 +122,9 @@ describe('filter', function(){      }); +    it('should accept miliseconds as date', function(){ +      expect(filter.date("123", "yyyy")).toEqual('1969'); +    });    });  });  | 
