Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f299fd5

Browse files
steinjakmhevery
authored andcommitted
fix(dateFilter): support sub-second precision on dateFilter
1 parent 05c88b8 commit f299fd5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/filter/filters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ dateFilter.$inject = ['$locale'];
320320
function dateFilter($locale) {
321321

322322

323-
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
323+
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
324324
function jsonStringToDate(string){
325325
var match;
326326
if (match = string.match(R_ISO8601_STR)) {

test/ng/filter/filtersSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,18 @@ describe('filters', function() {
270270
//no time
271271
expect(date('2003-09-10', format)).toEqual('2003-09 00');
272272
});
273+
274+
it('should support different degrees of subsecond precision', function () {
275+
var format = 'yyyy-MM-dd';
276+
277+
expect(date('2003-09-10T13:02:03.12345678Z', format)).toEqual('2003-09-10');
278+
expect(date('2003-09-10T13:02:03.1234567Z', format)).toEqual('2003-09-10');
279+
expect(date('2003-09-10T13:02:03.123456Z', format)).toEqual('2003-09-10');
280+
expect(date('2003-09-10T13:02:03.12345Z', format)).toEqual('2003-09-10');
281+
expect(date('2003-09-10T13:02:03.1234Z', format)).toEqual('2003-09-10');
282+
expect(date('2003-09-10T13:02:03.123Z', format)).toEqual('2003-09-10');
283+
expect(date('2003-09-10T13:02:03.12Z', format)).toEqual('2003-09-10');
284+
expect(date('2003-09-10T13:02:03.1Z', format)).toEqual('2003-09-10');
285+
});
273286
});
274287
});

0 commit comments

Comments
 (0)