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

Commit

Permalink
fix(dateFilter): support sub-second precision on dateFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
steinjak authored and mhevery committed Sep 6, 2012
1 parent 05c88b8 commit f299fd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
13 changes: 13 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit f299fd5

Please sign in to comment.