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

Commit 92bceb5

Browse files
SekibOmazicpetebacondarwin
authored andcommitted
fix(orderBy): correctly order by date values
Closes #6675 Closes #6746
1 parent 528f56a commit 92bceb5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/ng/filter/orderBy.js

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ function orderByFilter($parse){
153153
var t1 = typeof v1;
154154
var t2 = typeof v2;
155155
if (t1 == t2) {
156+
if (isDate(v1) && isDate(v2)) {
157+
v1 = v1.valueOf();
158+
v2 = v2.valueOf();
159+
}
156160
if (t1 == "string") {
157161
v1 = v1.toLowerCase();
158162
v2 = v2.toLowerCase();

test/ng/filter/orderBySpec.js

+30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ describe('Filter: orderBy', function() {
2323
expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['+b', '-a'])).toEqualData([{a:15, b:1}, {a:2, b:1}]);
2424
});
2525

26+
27+
it('should sort array by date predicate', function() {
28+
// same dates
29+
expect(orderBy([
30+
{ a:new Date('01/01/2014'), b:1 },
31+
{ a:new Date('01/01/2014'), b:3 },
32+
{ a:new Date('01/01/2014'), b:4 },
33+
{ a:new Date('01/01/2014'), b:2 }],
34+
['a', 'b']))
35+
.toEqualData([
36+
{ a:new Date('01/01/2014'), b:1 },
37+
{ a:new Date('01/01/2014'), b:2 },
38+
{ a:new Date('01/01/2014'), b:3 },
39+
{ a:new Date('01/01/2014'), b:4 }]);
40+
41+
// one different date
42+
expect(orderBy([
43+
{ a:new Date('01/01/2014'), b:1 },
44+
{ a:new Date('01/01/2014'), b:3 },
45+
{ a:new Date('01/01/2013'), b:4 },
46+
{ a:new Date('01/01/2014'), b:2 }],
47+
['a', 'b']))
48+
.toEqualData([
49+
{ a:new Date('01/01/2013'), b:4 },
50+
{ a:new Date('01/01/2014'), b:1 },
51+
{ a:new Date('01/01/2014'), b:2 },
52+
{ a:new Date('01/01/2014'), b:3 }]);
53+
});
54+
55+
2656
it('should use function', function() {
2757
expect(
2858
orderBy(

0 commit comments

Comments
 (0)