Skip to content

Commit

Permalink
Made date parsing slightly more lenient wrt mixed column types
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Feb 4, 2019
1 parent da240d2 commit f713544
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/perspective/src/js/DataAccessor/DateParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export class DateParser {
return null;
} else {
let val = input;
if (typeof val === "string") {
const type = typeof val;
if (val.getMonth) {
return val;
} else if (type === "string") {
val = moment(input, this.date_types, true);
if (!val.isValid() || this.date_types.length === 0) {
for (let candidate of this.date_candidates) {
Expand All @@ -55,8 +58,10 @@ export class DateParser {
return null;
}
return val.toDate();
} else if (type === "number") {
return new Date(val);
}
return val;
throw new Error(`Unparseable date ${val}`);
}
}
}
10 changes: 10 additions & 0 deletions packages/perspective/test/js/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,16 @@ module.exports = perspective => {
table.delete();
});

it("Handles datetime values with mixed formats", async function() {
var table = perspective.table({datetime: "datetime"});
table.update([{datetime: new Date(1549257586108)}, {datetime: "2019-01-30"}, {datetime: 11}]);
let view = table.view();
let result = await view.to_json();
expect(result).toEqual([{datetime: 1549257586108}, {datetime: 1548806400000}, {datetime: 11}]);
view.delete();
table.delete();
});

it("Handles date values", async function() {
var table = perspective.table({v: "date"});
table.update(data_4);
Expand Down

0 comments on commit f713544

Please sign in to comment.