[Pkg-javascript-commits] [dojo] 05/28: Make SimpleQueryEngine sort Dates correctly

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:46 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.8.6
in repository dojo.

commit 478b7be9e4182458d5451e1844bb25a7d61c0253
Author: Colin Snover <github.com at zetafleet.com>
Date:   Sat Nov 23 20:43:54 2013 +0000

    Make SimpleQueryEngine sort Dates correctly
    
    Fixes #17068.
    
    (cherry picked from commit 682f5d0dfeb4833842d476e6d8da946f6eb97e0f)
---
 store/util/SimpleQueryEngine.js |  3 +++
 tests/store/Memory.js           | 14 +++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/store/util/SimpleQueryEngine.js b/store/util/SimpleQueryEngine.js
index 57d67b4..6b74a91 100644
--- a/store/util/SimpleQueryEngine.js
+++ b/store/util/SimpleQueryEngine.js
@@ -88,6 +88,9 @@ return function(query, options){
 				for(var sort, i=0; sort = sortSet[i]; i++){
 					var aValue = a[sort.attribute];
 					var bValue = b[sort.attribute];
+					// valueOf enables proper comparison of dates
+					aValue = aValue != null ? aValue.valueOf() : aValue;
+					bValue = bValue != null ? bValue.valueOf() : bValue;
 					if (aValue != bValue){
 						return !!sort.descending == (aValue == null || aValue > bValue) ? -1 : 1;
 					}
diff --git a/tests/store/Memory.js b/tests/store/Memory.js
index b522f99..74bf254 100644
--- a/tests/store/Memory.js
+++ b/tests/store/Memory.js
@@ -3,11 +3,11 @@ dojo.require("dojo.store.Memory");
 (function(){
 	var store = new dojo.store.Memory({
 		data: [
-			{id: 1, name: "one", prime: false, mappedTo: "E"}, 
-			{id: 2, name: "two", even: true, prime: true, mappedTo: "D"}, 
-			{id: 3, name: "three", prime: true, mappedTo: "C"}, 
-			{id: 4, name: "four", even: true, prime: false, mappedTo: null}, 
-			{id: 5, name: "five", prime: true, mappedTo: "A"} 		
+			{id: 1, name: "one", prime: false, mappedTo: "E", date: new Date(1970, 0, 1) },
+			{id: 2, name: "two", even: true, prime: true, mappedTo: "D", date: new Date(1980, 1, 2) },
+			{id: 3, name: "three", prime: true, mappedTo: "C", date: new Date(1990, 2, 3) },
+			{id: 4, name: "four", even: true, prime: false, mappedTo: null, date: new Date(1972, 3, 6, 12, 1) },
+			{id: 5, name: "five", prime: true, mappedTo: "A", date: new Date(1972, 3, 6, 6, 2) }
 		]
 	});
 	tests.register("dojo.tests.store.Memory",
@@ -42,6 +42,10 @@ dojo.require("dojo.store.Memory");
 						return a.name < b.name ? -1 : 1;
 					}})[1].name, "two");
 				t.is(store.query(null, {sort:[{attribute:"mappedTo"}]})[4].name, "four");
+
+				t.is([ 1, 5, 4, 2, 3 ], store.query({}, { sort: [ { attribute: "date", descending: false } ] }).map(function (item) {
+					return item.id;
+				}));
 			},
 			function testQueryWithPaging(t){
 				t.is(store.query({prime: true}, {start: 1, count: 1}).length, 1);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list