diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index c56210f67b0d..b37921716c91 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -320,7 +320,7 @@ dateFilter.$inject = ['$locale']; function dateFilter($locale) { - var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; + var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; function jsonStringToDate(string){ var match; if (match = string.match(R_ISO8601_STR)) { diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index 554768820894..9e0a408aa55c 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -270,5 +270,18 @@ describe('filters', function() { //no time expect(date('2003-09-10', format)).toEqual('2003-09 00'); }); + + it('should support different degrees of subsecond precision', function () { + var format = 'yyyy-MM-dd'; + + expect(date('2003-09-10T13:02:03.12345678Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.1234567Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.123456Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.12345Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.1234Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.123Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.12Z', format)).toEqual('2003-09-10'); + expect(date('2003-09-10T13:02:03.1Z', format)).toEqual('2003-09-10'); + }); }); });