var stringMonth = function (m) {
switch (parseInt(m)) {
case 0:
return 'January';
case 1:
return 'February';
case 2:
return 'March';
case 3:
return 'April';
case 4:
return 'May';
case 5:
return 'June';
case 6:
return 'July';
case 7:
return 'August';
case 8:
return 'September';
case 9:
return 'October';
case 10:
return 'November';
case 11:
return 'December';
default:
return '#ERROR#';
}
}
var setUpCalendar = function (monthToShow) {
if (typeof monthToShow == 'string') monthToShow = new Date(monthToShow);
if (typeof monthToShow == 'object') monthToShow = monthToShow;
else monthToShow = new Date();
// Vars
var m = monthToShow.getMonth();
var y = monthToShow.getFullYear();
var numDays = new Date(y, m + 1, 0).getDate();
var fom = new Date(y, m, 1).getDay();
var lom = new Date(y, m + 1, 0).getDay();
var current = m == new Date().getMonth() && y == new Date().getFullYear();
// Correct for Sundays
if (fom == 0) fom = 7;
if (lom == 0) lom = 7;
// Correct the # of rows, say if 6
if ((fom == 7 && numDays > 29) || (fom == 6 && numDays == 31)) $('<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>').appendTo('tbody');
// or only 4 are needed
if (fom == 1 && numDays == 28) $('tbody tr:last-child').remove();
// Set title
var month = stringMonth(m);
$('table > caption').html(month + ' ' + y);
// Add starting space and remove extra cells
if (fom != 1) {
$('tbody > tr:first-child > td').eq(0).attr('colspan', fom - 1);
$('tbody > tr:first-child').children().slice(9 - fom).remove();
}
// Add ending space and remove extra cells
if (lom != 7) {
$('tbody > tr:last-child >...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.