fix(orderBy): compare timestamps when sorting date objects

Fixes #10512
Closes #10516
This commit is contained in:
Pawel Kozlowski
2014-12-18 19:16:24 +01:00
parent 56a7abd38f
commit 661f6d9ecf
2 changed files with 14 additions and 4 deletions

View File

@@ -172,14 +172,14 @@ function orderByFilter($parse) {
function objectToString(value) {
if (value === null) return 'null';
if (typeof value.toString === 'function') {
value = value.toString();
if (isPrimitive(value)) return value;
}
if (typeof value.valueOf === 'function') {
value = value.valueOf();
if (isPrimitive(value)) return value;
}
if (typeof value.toString === 'function') {
value = value.toString();
if (isPrimitive(value)) return value;
}
return '';
}

View File

@@ -79,6 +79,16 @@ describe('Filter: orderBy', function() {
{ a:new Date('01/01/2014'), b:3 }]);
});
it('should compare timestamps when sorting dates', function() {
expect(orderBy([
new Date('01/01/2015'),
new Date('01/01/2014')
])).toEqualData([
new Date('01/01/2014'),
new Date('01/01/2015')
]);
});
it('should use function', function() {
expect(