Created
September 7, 2017 19:52
-
-
Save Ben52/8de64c528deeb8d4facf2ea290fc023a to your computer and use it in GitHub Desktop.
Get range of dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tnks !