mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
fix(orderBy): compare timestamps when sorting date objects
Fixes #10512 Closes #10516
This commit is contained in:
@@ -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 '';
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user