Skip to content

Instantly share code, notes, and snippets.

@andresfelipemendez
Last active August 29, 2015 14:16
Show Gist options
  • Save andresfelipemendez/e2445917e6a7b965dd7b to your computer and use it in GitHub Desktop.
Save andresfelipemendez/e2445917e6a7b965dd7b to your computer and use it in GitHub Desktop.
calendar generator
/*jslint plusplus: true */
function daysInMonth(month, year) {
'use strict';
return new Date(year, month, 0).getDate();
}
function generateCalendar(year) {
'use strict';
var calendar = {},
month,
date,
days = 1,
day;
calendar[year] = {};
for (month = 1; month <= 12; month++) {
calendar[year][month] = {};
for (date = 1; date <= daysInMonth(month, year); date++) {
days++;
day = days % 7;
calendar[year][month][date] = day;
}
}
return calendar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment