JSFiddle - React, Tailwind, and code Playground
HTML
<pre id="console"></pre>
JavaScript
log(
date_range(new Date('Oct 2 2015'), new Date('Apr 23 2016'))
);
function date_range(from, to) {
if (to instanceof Date === false)
to = new Date();
if (from instanceof Date === false || from > to)
from = to;
var results = [];
while (from.getTime() !== to.getTime()) {
results.push(date_to_object(from));
from.setDate(from.getDate() +1);
}
results.push(date_to_object(to));
return results;
}
function date_to_object(date) {
return {
year: date.getFullYear(),
month: date.getMonth() +1,
day: date.getDate()
};
}
function log(msg) {
$('#console').append(JSON.stringify(msg, null, 2));
}