Last active
December 22, 2016 20:21
-
-
Save frankhale/ae1bce89c09818f2168c7f210a0dc2f4 to your computer and use it in GitHub Desktop.
Print a list of weeks of the year starting on Jan 1
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"), | |
_ = require("lodash"); | |
function getWeeksOfYearList(startDate, endDate) { | |
let dates = [], | |
keepGoing = true, | |
start = moment(startDate), | |
end = moment(endDate), | |
rolling = start; | |
while(keepGoing) { | |
dates.push(rolling.format("DD MMM YYYY")); | |
rolling = rolling.add(7, "days"); | |
dates.push(rolling.format("DD MMM YYYY")); | |
if(rolling > end) { | |
keepGoing = false; | |
} | |
} | |
return _.chunk(dates, 2); | |
} | |
_.forEach(getWeeksOfYearList("20160101", "20161231"), (w) => { | |
console.log(`start: ${w[0]} | end: ${w[1]}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment