Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date filter issue #478

Merged
merged 2 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp/perspective/src/cpp/emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ namespace binding {
term = mktscalar(filter[2].as<bool>());
} break;
case DTYPE_DATE: {
term = mktscalar(t_date(filter[2].as<std::int32_t>()));
val parsed_date = j_date_parser.call<val>("parse", filter[2]);
term = mktscalar(jsdate_to_t_date(parsed_date));
} break;
case DTYPE_TIME: {
val parsed_date = j_date_parser.call<val>("parse", filter[2]);
Expand Down
45 changes: 41 additions & 4 deletions packages/perspective/test/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -110,6 +110,43 @@ module.exports = perspective => {
view.delete();
table.delete();
});

describe("filtering on date column", function() {
const schema = {
w: "date"
};

const date_results = [
{w: +new Date(1535760000000)}, // Fri Aug 31 2018 20:00:00 GMT-0400
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the schema converts the datetime above to a date in the result set

{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();
});
});
});

describe("EQ", function() {
Expand Down