[Pkg-javascript-commits] [dojo] 05/27: Make SimpleQueryEngine sort Dates correctly
David Prévot
taffit at moszumanska.debian.org
Sun Sep 14 16:23:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.7.6
in repository dojo.
commit 2d440d7b0d32d93f66211e5cb732b3979c6855a8
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)
Conflicts:
store/util/SimpleQueryEngine.js
tests/store/Memory.js
---
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 2b1c262..6b74b8b 100644
--- a/store/util/SimpleQueryEngine.js
+++ b/store/util/SimpleQueryEngine.js
@@ -87,6 +87,9 @@ return function(query, options){
for(var sort, i=0; sort = options.sort[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 > bValue ? -1 : 1;
}
diff --git a/tests/store/Memory.js b/tests/store/Memory.js
index edf8081..8676a1c 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},
- {id: 2, name: "two", even: true, prime: true},
- {id: 3, name: "three", prime: true},
- {id: 4, name: "four", even: true, prime: false},
- {id: 5, name: "five", prime: true}
+ {id: 1, name: "one", prime: false, date: new Date(1970, 0, 1) },
+ {id: 2, name: "two", even: true, prime: true, date: new Date(1980, 1, 2) },
+ {id: 3, name: "three", prime: true, date: new Date(1990, 2, 3) },
+ {id: 4, name: "four", even: true, prime: false, date: new Date(1972, 3, 6, 12, 1) },
+ {id: 5, name: "five", prime: true, date: new Date(1972, 3, 6, 6, 2) }
]
});
tests.register("dojo.tests.store.Memory",
@@ -34,6 +34,10 @@ dojo.require("dojo.store.Memory");
function testQueryWithSort(t){
t.is(store.query({prime: true}, {sort:[{attribute:"name"}]}).length, 3);
t.is(store.query({even: true}, {sort:[{attribute:"name"}]})[1].name, "two");
+
+ 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