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

Commit 661f6d9

Browse files
fix(orderBy): compare timestamps when sorting date objects
Fixes #10512 Closes #10516
1 parent 56a7abd commit 661f6d9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/ng/filter/orderBy.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ function orderByFilter($parse) {
172172

173173
function objectToString(value) {
174174
if (value === null) return 'null';
175-
if (typeof value.toString === 'function') {
176-
value = value.toString();
177-
if (isPrimitive(value)) return value;
178-
}
179175
if (typeof value.valueOf === 'function') {
180176
value = value.valueOf();
181177
if (isPrimitive(value)) return value;
182178
}
179+
if (typeof value.toString === 'function') {
180+
value = value.toString();
181+
if (isPrimitive(value)) return value;
182+
}
183183
return '';
184184
}
185185

test/ng/filter/orderBySpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ describe('Filter: orderBy', function() {
7979
{ a:new Date('01/01/2014'), b:3 }]);
8080
});
8181

82+
it('should compare timestamps when sorting dates', function() {
83+
expect(orderBy([
84+
new Date('01/01/2015'),
85+
new Date('01/01/2014')
86+
])).toEqualData([
87+
new Date('01/01/2014'),
88+
new Date('01/01/2015')
89+
]);
90+
});
91+
8292

8393
it('should use function', function() {
8494
expect(

0 commit comments

Comments
 (0)