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

fix(date): date filter now correctly formats high precision date-times #2280

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ function dateFilter($locale) {
tzMin = int(match[9] + match[11]);
}
dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3]));
timeSetter.call(date, int(match[4]||0) - tzHour, int(match[5]||0) - tzMin, int(match[6]||0), int(match[7]||0));
var h = int(match[4]||0) - tzHour;
var m = int(match[5]||0) - tzMin
var s = int(match[6]||0);
var ms = Math.round(parseFloat('0.' + (match[7]||0)) * 1000);
timeSetter.call(date, h, m, s, ms);
return date;
}
return string;
Expand Down
36 changes: 20 additions & 16 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,23 @@ describe('filters', function() {
it('should support various iso8061 date strings with timezone as input', function() {
var format = 'yyyy-MM-dd ss';

var localDay = new Date(Date.UTC(2003, 9, 10, 13, 2, 3, 0)).getDate();

//full ISO8061
expect(date('2003-09-10T13:02:03.000Z', format)).toEqual('2003-09-10 03');
expect(date('2003-09-10T13:02:03.000Z', format)).toEqual('2003-09-' + localDay + ' 03');

expect(date('2003-09-10T13:02:03.000+00:00', format)).toEqual('2003-09-10 03');
expect(date('2003-09-10T13:02:03.000+00:00', format)).toEqual('2003-09-' + localDay + ' 03');

expect(date('20030910T033203-0930', format)).toEqual('2003-09-10 03');
expect(date('20030910T033203-0930', format)).toEqual('2003-09-' + localDay + ' 03');

//no millis
expect(date('2003-09-10T13:02:03Z', format)).toEqual('2003-09-10 03');
expect(date('2003-09-10T13:02:03Z', format)).toEqual('2003-09-' + localDay + ' 03');

//no seconds
expect(date('2003-09-10T13:02Z', format)).toEqual('2003-09-10 00');
expect(date('2003-09-10T13:02Z', format)).toEqual('2003-09-' + localDay + ' 00');

//no minutes
expect(date('2003-09-10T13Z', format)).toEqual('2003-09-10 00');
expect(date('2003-09-10T13Z', format)).toEqual('2003-09-' + localDay + ' 00');
});


Expand All @@ -331,16 +333,18 @@ describe('filters', function() {
});

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');
var format = 'yyyy-MM-dd ss';

var localDay = new Date(Date.UTC(2003, 9-1, 10, 13, 2, 3, 123)).getDate();

expect(date('2003-09-10T13:02:03.12345678Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.1234567Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.123456Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.12345Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.1234Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.123Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.12Z', format)).toEqual('2003-09-' + localDay + ' 03');
expect(date('2003-09-10T13:02:03.1Z', format)).toEqual('2003-09-' + localDay + ' 03');
});
});
});