Last active
August 29, 2015 14:16
-
-
Save andresfelipemendez/e2445917e6a7b965dd7b to your computer and use it in GitHub Desktop.
calendar generator
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
/*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