Created
January 27, 2017 11:42
-
-
Save cankemik/88a1c5a4a2974667a5dd80ca2012270c to your computer and use it in GitHub Desktop.
Year Divided in Weeks
This file contains 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
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