chunk-date-range
chunk-date-range copied to clipboard
months testing seems to be invalid
var assert = require('assert');
var chunk = require('./');
var Dates = require('date-math');
const getDay = (time, isString) => time.getDate();
const fromDays = days =>
new Date(new Date()
.setDate(getDay(new Date()) - days));
describe('chunk-date-range', function() {
describe('by duration', function() {
describe('month', () => {
const duration = 'month';
it('31 days is 1', () => {
const start = fromDays(31);
console.log({ start });
const chunks = chunk(start, new Date(), duration);
assert.equal(chunks.length, 1);
});
it('32 days is 2', () => { // FAILS with 1 chunk
const start = fromDays(32);
console.log({ start });
const chunks = chunk(start, new Date(), duration);
assert.equal(chunks.length, 2);
});
});
});
function verify(chunks, start, end) {
assert.equal(+chunks[0].start, +start);
assert.equal(+chunks[chunks.length - 1].end, +end);
chunks.forEach(function(chunk, i) {
var next = chunks[i + 1];
if (!next) return;
assert.equal(+chunk.end, +next.start);
});
}
});
Ok, fixed the test showing possible problems.
See #2