[Pkg-javascript-commits] [dojo] 12/21: Make SimpleQueryEngine sort Dates correctly
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:53 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.9.2
in repository dojo.
commit 35032e6de8d6b36417382b68c72f893c13c15b64
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 005a6ab..1a1ee56 100644
--- a/tests/store/Memory.js
+++ b/tests/store/Memory.js
@@ -1,11 +1,11 @@
define(["doh", "dojo/store/Memory"], function(doh, Memory){
var store = new 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) }
]
});
doh.register("dojo.tests.store.Memory",
@@ -40,6 +40,10 @@ define(["doh", "dojo/store/Memory"], function(doh, 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