aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/filters.js10
-rw-r--r--test/FiltersSpec.js4
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');
+ });
});
});