var NewCalendarAssistant = (function(){ 'use strict'; var months = [ newMonth("January", 31, 3), newMonth("February", 28, 6), newMonth("March", 31, 6), newMonth("April", 30, 2), newMonth("May", 31, 4), newMonth("June", 30, 0), newMonth("July", 31, 2), newMonth("August", 31, 5), newMonth("September", 30, 1), newMonth("October", 31, 3), newMonth("November", 30, 6), newMonth("December", 31, 1) ], weekdays = [ newWeekday("Sunday", "Sn"), newWeekday("Monday", "Mo"), newWeekday("Tuesday", "Tu"), newWeekday("Wednesday", "We"), newWeekday("Thursday", "Th"), newWeekday("Friday", "Fr"), newWeekday("Saturday", "Sa") ]; function Day(){ } function newWeekday(title, abbrv){ return new Weekday(title, abbrv); } function Weekday(title, abbrv){ this.title = title; this.abbrv = abbrv; } function newMonth(title, numDays, monthCode){ return new Month(title, numDays, monthCode); } function Month(title, numDays, monthValue, monthCode){ this.title = title; this.numDays = numDays; this.monthValue = monthValue; // Used as a match value to determine the days of the week this.monthCode = monthCode; // Array of days in the form of []Day this.days = new Array(numDays); } function isLeapYear(year){ if(isNaN(year)){ return false; } if(year % 4 !== 0){ return false; } if(year % 100 === 0 && year % 400 !== 0){ return false; } return true; } function getNumberOfDays(month, year) { var v = l[g[month] - 1]; if(month === "February" && isLeapYear(year)){ v++; } return v; } })(); function CalendarAssistant() { function p(a, d) { function b(a, b) { var d = []; c(a, b, function(a, b) { var c = b + a.date, e = h(a.month, c, a.year); e.number = c; d.push(e) }); return d } function e() { var c = q(a.month, a.year); return b(a, f).concat(p(h(c.name, 1, c.year), d - f)) } function c(a, b, d) { for (var c = 0; c < b; c++) d(a, c) } var f = l[g[a.month] - 1] - a.date + 1; return f >= d ? b(a, d) : e() } function h(a, d, b) { var e = parseFloat(b.toString().substr(2, 2)), c = { January: 3, February: 6, March: 6, April: 2, May: 4, June: 0, July: 2, August: 5, September: 1, October: 3, November: 6, December: 1 }[a], f = e / 4; 0 != f % 1 ? f = Math.floor(f) : "January" != a && "February" != a || (0 != e || 0 != e % 400) && 0 == e || (c -= 1); e = "Saturday Sunday Monday Tuesday Wednesday Thursday Friday".split(" ")[(4 + e + f + c + parseFloat(d)) % 7]; return new s(a, d, b, e, e.substr(0, 3)) } function s(a, d, b, e, c) { this.month = a; this.monthValue = g[a]; this.name = e; this.element = null; this.abbreviation = c || null; this.number = this.className = null; this.__defineGetter__("date", function() { return d }); this.__defineSetter__("date", function() { return !1 }); this.__defineGetter__("year", function() { return b }); this.__defineSetter__("year", function() { return !1 }) } function q(a, d) { var b = null, b = g[a]; void 0 == d && (d = n().year); "December" !== a ? b = k[b] : (b = k[0], d++); return { name: b, year: d } } function n() { var a = new Date; return h(r(a.getMonth()), a.getDate(), a.getFullYear()) } function r(a) { return t[a] } var k = "January February March April May June July August September October November December".split(" "), m = [{ name: "Sunday", abbreviation: "Sn" }, { name: "Monday", abbreviation: "Mo" }, { name: "Tuesday", abbreviation: "Tu" }, { name: "Wednesday", abbreviation: "We" }, { name: "Thursday", abbreviation: "Th" }, { name: "Friday", abbreviation: "Fr" }, { name: "Saturday", abbreviation: "Sa" }], u = { Sunday: 0, Monday: 1, Tuesday: 2, Wednesday: 3, Thursday: 4, Friday: 5, Saturday: 6 }, g = { January: 1, February: 2, March: 3, April: 4, May: 5, June: 6, July: 7, August: 8, September: 9, October: 10, November: 11, December: 12 }, t = "January February March April May June July August September October November December".split(" "), l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; this.numberofdays = l; this.getDaysOfWeek = function(a) { a = a.name; for (var d = [], b = [], e = null, c = 0, f = m.length; c < f; c++) m[c].name == a && (e = c), null === e ? d.push(m[c]) : b.push(m[c]); return b.concat(d) }; this.getNextMonth = q; this.getPreviousMonth = function(a, d) { var b = null, b = g[a] - 1; void 0 == d && (d = n().year); "January" !== a ? b = k[b - 1] : (b = k[k.length - 1], d--); return { name: b, year: d } }; this.getDaysBefore = function(a) { return u[a] }; this.getMonth = function(a, d) { for (var b = l[g[a] - 1], e = [], c = 1; c <= b; c++) { var f = h(a, c, d); f.number = c; e.push(f) } return e }; this.getCurrentDay = n; this.getDays = p; this.getDay = h; this.getMonthValue = function(a) { return g[a] }; this.getMonthName = r; this.getNumberOfDays = function(a) { return l[g[a] - 1] } };