Created
March 15, 2015 23:06
-
-
Save vukicevic/257c8fa9761cf76fda65 to your computer and use it in GitHub Desktop.
Calendar widget dates generator using ES6
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
function *calendar (month, year) { | |
var c = new Date(year, month, 0).getDate(); | |
var l = new Date(year, month - 1, 0).getDate(); | |
var o = new Date(year, month - 1, 1).getDay(); | |
var p = o > 0 ? 1 - o : -6; | |
var m = 42 + p; | |
while (p < m) | |
yield p < 0 ? ++p + l : p < c ? ++p : ++p % c; | |
} | |
for (var i of calendar(3, 2015)) | |
console.log(i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment