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

Commit

Permalink
fix(orderBy): correctly order by date values
Browse files Browse the repository at this point in the history
Closes #6675
Closes #6746
  • Loading branch information
SekibOmazic authored and petebacondarwin committed Jul 15, 2014
1 parent 528f56a commit 92bceb5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ function orderByFilter($parse){
var t1 = typeof v1;
var t2 = typeof v2;
if (t1 == t2) {
if (isDate(v1) && isDate(v2)) {
v1 = v1.valueOf();
v2 = v2.valueOf();
}
if (t1 == "string") {
v1 = v1.toLowerCase();
v2 = v2.toLowerCase();
Expand Down
30 changes: 30 additions & 0 deletions test/ng/filter/orderBySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,36 @@ describe('Filter: orderBy', function() {
expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['+b', '-a'])).toEqualData([{a:15, b:1}, {a:2, b:1}]);
});


it('should sort array by date predicate', function() {
// same dates
expect(orderBy([
{ a:new Date('01/01/2014'), b:1 },
{ a:new Date('01/01/2014'), b:3 },
{ a:new Date('01/01/2014'), b:4 },
{ a:new Date('01/01/2014'), b:2 }],
['a', 'b']))
.toEqualData([
{ a:new Date('01/01/2014'), b:1 },
{ a:new Date('01/01/2014'), b:2 },
{ a:new Date('01/01/2014'), b:3 },
{ a:new Date('01/01/2014'), b:4 }]);

// one different date
expect(orderBy([
{ a:new Date('01/01/2014'), b:1 },
{ a:new Date('01/01/2014'), b:3 },
{ a:new Date('01/01/2013'), b:4 },
{ a:new Date('01/01/2014'), b:2 }],
['a', 'b']))
.toEqualData([
{ a:new Date('01/01/2013'), b:4 },
{ a:new Date('01/01/2014'), b:1 },
{ a:new Date('01/01/2014'), b:2 },
{ a:new Date('01/01/2014'), b:3 }]);
});


it('should use function', function() {
expect(
orderBy(
Expand Down

0 comments on commit 92bceb5

Please sign in to comment.