From ef043c3b7bb64072dd796f147453eb279388f99c Mon Sep 17 00:00:00 2001 From: Josh Hawkins Date: Thu, 7 Mar 2019 14:04:31 -0500 Subject: [PATCH 1/2] Expose date filter issue in a unit test --- packages/perspective/test/js/filters.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/perspective/test/js/filters.js b/packages/perspective/test/js/filters.js index 7f66f10510..12b44ae504 100644 --- a/packages/perspective/test/js/filters.js +++ b/packages/perspective/test/js/filters.js @@ -110,6 +110,23 @@ module.exports = perspective => { view.delete(); table.delete(); }); + + it("w < date as string", async function() { + const schema = { + w: "date", + x: "integer", + y: "string", + z: "boolean" + }; + var table = perspective.table(schema); + var view = table.view({ + filter: [["w", "<", "10/01/2018"]] + }); + let json = await view.to_json(); + expect(json).toEqual([r_date_range_data[0]]); + view.delete(); + table.delete(); + }); }); describe("EQ", function() { From 9d0ed3f7eaf4a2edfc466499f1f16fe793784dc0 Mon Sep 17 00:00:00 2001 From: Josh Hawkins Date: Thu, 7 Mar 2019 16:32:58 -0500 Subject: [PATCH 2/2] Fix date filtering and add another test on < --- cpp/perspective/src/cpp/emscripten.cpp | 3 +- packages/perspective/test/js/filters.js | 52 +++++++++++++++++-------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/cpp/perspective/src/cpp/emscripten.cpp b/cpp/perspective/src/cpp/emscripten.cpp index d1f03ef1b9..63f45bd92a 100644 --- a/cpp/perspective/src/cpp/emscripten.cpp +++ b/cpp/perspective/src/cpp/emscripten.cpp @@ -167,7 +167,8 @@ namespace binding { term = mktscalar(filter[2].as()); } break; case DTYPE_DATE: { - term = mktscalar(t_date(filter[2].as())); + val parsed_date = j_date_parser.call("parse", filter[2]); + term = mktscalar(jsdate_to_t_date(parsed_date)); } break; case DTYPE_TIME: { val parsed_date = j_date_parser.call("parse", filter[2]); diff --git a/packages/perspective/test/js/filters.js b/packages/perspective/test/js/filters.js index 12b44ae504..cb00771300 100644 --- a/packages/perspective/test/js/filters.js +++ b/packages/perspective/test/js/filters.js @@ -18,10 +18,10 @@ var rdata = [{w: +now, x: 1, y: "a", z: true}, {w: +now, x: 2, y: "b", z: false} // starting from 09/01/2018 to 12/01/2018 var date_range_data = [ - {w: new Date(1535778060000), x: 1, y: "a", z: true}, - {w: new Date(1538370060000), x: 2, y: "b", z: false}, - {w: new Date(1541048460000), x: 3, y: "c", z: true}, - {w: new Date(1543644060000), x: 4, y: "d", z: false} + {w: new Date(1535778060000), x: 1, y: "a", z: true}, // Sat Sep 01 2018 01:01:00 GMT-0400 + {w: new Date(1538370060000), x: 2, y: "b", z: false}, // Mon Oct 01 2018 01:01:00 GMT-0400 + {w: new Date(1541048460000), x: 3, y: "c", z: true}, // Thu Nov 01 2018 01:01:00 GMT-0400 + {w: new Date(1543644060000), x: 4, y: "d", z: false} // Sat Dec 01 2018 01:01:00 GMT-0500 ]; var r_date_range_data = [ @@ -111,21 +111,41 @@ module.exports = perspective => { table.delete(); }); - it("w < date as string", async function() { + describe("filtering on date column", function() { const schema = { - w: "date", - x: "integer", - y: "string", - z: "boolean" + w: "date" }; - var table = perspective.table(schema); - var view = table.view({ - filter: [["w", "<", "10/01/2018"]] + + const date_results = [ + {w: +new Date(1535760000000)}, // Fri Aug 31 2018 20:00:00 GMT-0400 + {w: +new Date(1538352000000)}, // Sun Sep 30 2018 20:00:00 GMT-0400 + {w: +new Date(1541030400000)}, // Wed Oct 31 2018 20:00:00 GMT-0400 + {w: +new Date(1543622400000)} // Fri Nov 30 2018 19:00:00 GMT-0500 + ]; + + it("w > date as string", async function() { + var table = perspective.table(schema); + table.update(date_range_data); + var view = table.view({ + filter: [["w", ">", "10/01/2018"]] + }); + let json = await view.to_json(); + expect(json).toEqual(date_results.slice(2, 4)); + view.delete(); + table.delete(); + }); + + it("w < date as string", async function() { + var table = perspective.table(schema); + table.update(date_range_data); + var view = table.view({ + filter: [["w", "<", "10/01/2018"]] + }); + let json = await view.to_json(); + expect(json).toEqual([date_results[0]]); + view.delete(); + table.delete(); }); - let json = await view.to_json(); - expect(json).toEqual([r_date_range_data[0]]); - view.delete(); - table.delete(); }); });