Skip to content

Commit

Permalink
range-date tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer4web committed Jul 3, 2018
1 parent d2865be commit b3261a1
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions test/range-date.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,31 @@
'2016-08-27',
'2015-01-03',
'2021-12-31'
].forEach(dateString => {
const date = new Date(dateString),
localString = column._toLocalISOString(date);
// if (date.getTimezoneOffset() !== 0) {
// assert.notEqual(localString, date.toISOString().substr(0, 23));
// } else {
// assert.equal(localString, date.toISOString().substr(0, 23));
// }
assert.equal(new Date(localString).setHours(0, 0, 0), new Date(dateString).setHours(0, 0, 0));
].forEach(value => {
const date = column.toValue(value);
assert.equal(
column._toLocalISOString(date),
column.toValue(date.getTime() - date.getTimezoneOffset() * 6e4).toISOString().slice(0, 23)
);
});

done();
});

test('changing filter updates _filterInput', function (done) {
const min = column.toValue('2015-03-18'),
max = column.toValue('2023-03-21');

assert.isNull(column.filter.min);
assert.isNull(column.filter.max);

column.filter = {
min: new Date('2015-03-18'),
max: new Date('2023-03-21')
};

assert.equal(column._filterInput.min, '2015-03-18', 'Expect _filterInput.min to be local ISO String');
assert.equal(column._filterInput.max, '2023-03-21', 'Expect _filterInput.max to be local ISO String');
column.filter = {min, max};
const {max: fMax, min: fMin} = column._filterInput;
assert.equal(fMin, column._toLocalISOString(min).slice(0, 10), 'Expect _filterInput.min to be local ISO String');
assert.equal(fMax, column._toLocalISOString(max).slice(0, 10), 'Expect _filterInput.max to be local ISO String');

assert.equal(new Date(column._filterInput.min).getTime(), column.filter.min.getTime(), 'Expect min input and filter to be equal as dates');
assert.equal(new Date(column._filterInput.max).getTime(), column.filter.max.getTime(), 'Expect max input and filter to be equal as dates');
assert.equal(column.toValue(fMin).getTime(), min.getTime(), 'Expect min input and filter to be equal as dates');
assert.equal(column.toValue(fMax).getTime(), max.getTime(), 'Expect max input and filter to be equal as dates');

done();
});
Expand Down Expand Up @@ -284,10 +281,14 @@
// });

test('_toInputString converts datetime to local string', function (done) {
// assert.equal(column._toInputString(new Date(86400000)), '1970-01-02T02:00:00');
assert.equal(column._toInputString(new Date('2006-07-14T07:05:39')), '2006-07-14T07:05:39');
assert.equal(column._toInputString(new Date('2021-12-03T09:26:04')), '2021-12-03T09:26:04');
assert.equal(column._toInputString(new Date('2114-04-22T04:09:00')), '2114-04-22T04:09:00');
[
86400000,
'2006-07-14T07:05:39',
'2021-12-03T09:26:04',
'2114-04-22T04:09:00'
].forEach(value =>
assert.equal(column._toInputString(value), column._toLocalISOString(column.toValue(value)).slice(0, 19))
);
done();
});

Expand All @@ -296,12 +297,9 @@
'2021-12-03T11:26:04',
'2016-04-22T07:09:00',
'2017-01-16T09:19:38'
].forEach(dateString => {
const date = new Date(dateString),
hashString = column._toHashString(date);

assert.equal(hashString, date.toISOString().substr(0, 19).replace(/:/g, '.'));
});
].forEach(date =>
assert.equal(column._toHashString(date), column.toValue(date).toISOString().substr(0, 19).replace(/:/g, '.'))
);
done();
});

Expand Down

0 comments on commit b3261a1

Please sign in to comment.