Skip to content

Instantly share code, notes, and snippets.

@Ben52
Created September 7, 2017 19:52
Show Gist options
  • Save Ben52/8de64c528deeb8d4facf2ea290fc023a to your computer and use it in GitHub Desktop.
Save Ben52/8de64c528deeb8d4facf2ea290fc023a to your computer and use it in GitHub Desktop.
Get range of dates
const moment = require('moment');
function getRangeOfDates(start, end, key, arr = [start.startOf(key)]) {
if(start.isAfter(end)) throw new Error('start must precede end')
const next = moment(start).add(1, key).startOf(key);
if(next.isAfter(end, key)) return arr;
return getRangeOfDates(next, end, key, arr.concat(next));
}
@itlpps
Copy link

itlpps commented Jun 26, 2018

Tnks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment