Skip to content
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
2 changes: 2 additions & 0 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var CONSTANT = {
// object format
NONE: 'NONE',
ARRAY: 'ARRAY',
DATE_OBJECT: 'DATE_OBJECT',
OBJECT: 'OBJECT'
},

Expand Down Expand Up @@ -118,6 +119,7 @@ CONSTANT.VALIDATORS = [
// true/false, 0/1
CONSTANT.DATA_TYPES.BOOLEAN,
CONSTANT.DATA_TYPES.ARRAY,
CONSTANT.DATA_TYPES.DATE_OBJECT,
CONSTANT.DATA_TYPES.OBJECT,

// prefix/postfix rules
Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ var Utils = {
return Array.isArray(value);
},

isDateObject: function isDateObject(value) {
// Note: invalid Dates return true as well as valid Dates.
return value instanceof Date;
},

isObject: function isObject(value) {
return value === Object(value) && typeof value !== 'function' && !Array.isArray(value)
},
Expand Down
1 change: 1 addition & 0 deletions src/validator-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ VALIDATOR_MAP[DATA_TYPES.PAIR_GEOMETRY_FROM_STRING] =
// basic boolean: true/false, 0/1
VALIDATOR_MAP[DATA_TYPES.BOOLEAN] = Utils.isBoolean;
VALIDATOR_MAP[DATA_TYPES.ARRAY] = Utils.isArray;
VALIDATOR_MAP[DATA_TYPES.DATE_OBJECT] = Utils.isDateObject;
VALIDATOR_MAP[DATA_TYPES.OBJECT] = Utils.isObject;

// prefix/postfix rules: '$30.00', '10.05%'
Expand Down
24 changes: 24 additions & 0 deletions test/time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ test('Analyzer: date validator', function t(assert) {
result = Analyzer.computeColMeta(arr);
assert.equal(result[0].type, 'DATETIME', 'Interprets col as datetime correctly');

arr = [
{col: new Date(2016, 1, 1)},
{col: new Date(2017, 2, 2)},
{col: new Date(2018, 3, 3)}
];
result = Analyzer.computeColMeta(arr);
assert.equal(result[0].type, 'DATE_OBJECT', 'Interprets valid Dates created w/ component ctor as date objects');

arr = [
{col: new Date('2016-07-24T19:53:38.000Z')},
{col: new Date('2016-07-24T12:55:36.000Z')},
{col: new Date('2016-07-24T19:55:36.000Z')}
];
result = Analyzer.computeColMeta(arr);
assert.equal(result[0].type, 'DATE_OBJECT', 'Interprets valid Dates created w/ timestamp ctor as date objects');

arr = [
{col: new Date('this is')},
{col: new Date('not a')},
{col: new Date('valid date')}
];
result = Analyzer.computeColMeta(arr);
assert.equal(result[0].type, 'DATE_OBJECT', 'Interprets invalid Dates as date objects');

assert.end();
});
/* eslint-enable max-statements*/