Skip to content

Instantly share code, notes, and snippets.

@vukicevic
Created March 15, 2015 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vukicevic/257c8fa9761cf76fda65 to your computer and use it in GitHub Desktop.
Save vukicevic/257c8fa9761cf76fda65 to your computer and use it in GitHub Desktop.
Calendar widget dates generator using ES6
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