Skip to content

Instantly share code, notes, and snippets.

@frankhale
Last active December 22, 2016 20:21
Show Gist options
  • Save frankhale/ae1bce89c09818f2168c7f210a0dc2f4 to your computer and use it in GitHub Desktop.
Save frankhale/ae1bce89c09818f2168c7f210a0dc2f4 to your computer and use it in GitHub Desktop.
Print a list of weeks of the year starting on Jan 1
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