Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Year Divided in Weeks
let weeks = {};
for (var i = 1; i < 366; i++) {
if (((i - 1) % 7) == 0) {
weeks[Object.keys(weeks).length + 1] = {dates: [{
date: new Date(new Date().getFullYear(), 0, i),
current: (new Date(new Date().getFullYear(), 0, i).getDate() == new Date().getDate() && new Date(new Date().getFullYear(), 0, i).getMonth() == new Date().getMonth())
}]}
} else {
weeks[Object.keys(weeks).length].dates.push({
date: new Date(new Date().getFullYear(), 0, i),
current: (new Date(new Date().getFullYear(), 0, i).getDate() == new Date().getDate() && new Date(new Date().getFullYear(), 0, i).getMonth() == new Date().getMonth())
})
}
}
console.log(weeks);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.