/* external_date_functions.js * * Purpose: Sample external date functions for JavaScript calendar * Author: Richard Pike) * Website: http://calendar.pikesys.com * * my_date returns an alternate date string corresponding to the given Gregorian date * my_holiday returns an appropriate holiday text string for the given Gregorian date * my_alt_holiday returns an appropriate alternate holiday string for the given Gregorian date * */ function makeArray() { this[0] = makeArray.arguments.length; for (i = 0; i < makeArray.arguments.length; i = i + 1) this[i+1] = makeArray.arguments[i]; } var altMonthNames = new makeArray("Red", "Yellow", "Blue","Green","Purple","Orange","Cyan","Magenta","Goldenrod","Brown","Black","White"); var altMonths = new Array; // altMonths constructor function altMonth(startdate, monthnumber) { this.startdate = startdate; this.month = monthnumber; } function DefineAltMonth(startdate, monthnumber) { altMonths[altMonths.length] = new altMonth(startdate, monthnumber); } // these could be defined in external JavaScript such as altdates.js (the last altMonth defined will not show because endate is unknown!) DefineAltMonth(20040404, 1); DefineAltMonth(20040505, 2); DefineAltMonth(20040606, 3); DefineAltMonth(20040707, 4); DefineAltMonth(20040808, 5); DefineAltMonth(20040909, 6); DefineAltMonth(20041010, 7); DefineAltMonth(20041111, 8); DefineAltMonth(20041212, 9); DefineAltMonth(20050113, 10); DefineAltMonth(20050214, 11); DefineAltMonth(20050315, 12); DefineAltMonth(20050416, 1); function my_date(day, month, year, style) { if (!style) style = 0; var mo = 0; var dy, yr; var dateString = ""; ymd = day + month*100 + year*10000; for (i=1; i= altMonths[i-1].startdate && ymd < altMonths[i].startdate) { mo = altMonths[i-1].month; startDay = altMonths[i-1].startdate%100; startMonth = ((altMonths[i-1].startdate-startDay)/100)%100; if (month == startMonth) { dy = day - startDay +1; } else { ym = month + year*100; prevYM = PrevYearMonth(ym); prevM = prevYM%100; prevY = (prevYM - prevM)/100; eom = NumDaysIn(prevM, prevY); dy = day + (eom - startDay +1); } yr = year - 1970; break; } } if (mo > 0) { if (style == 0) { // day monthnum year dateString = dy + ' ' + mo + ' ' + yr; } else if (style == 1) { // monthname year dateString = altMonthNames[mo] + ' ' + yr; } else if (style == 2) { // day monthname dateString = dy + ' ' + altMonthNames[mo]; } else if (style == 3) { // monthname day dateString = altMonthNames[mo] + ' ' + dy; } else if (style == 4) { // day monthname year dateString = dy + ' ' + altMonthNames[mo] + ' ' + yr; } } return dateString; } function my_holiday(day, month, year) { //alert("my_holiday("+day+","+month+","+year+")"); var holString = ""; // some Standard civil holidays if (month == 1 && day == 1) holString = "New Year's Day"; else if (month == 12 && day == 24) holString = "Christmas Eve"; else if (month == 12 && day == 25) holString = "Christmas Day"; else if (month == 12 && day == 31) holString = "New Year's Eve"; else if (month == 02 && day == 13 && year == 2017) holString = "Family Day"; else if (month == 04 && day == 14 && year == 2017) holString = "Good Friday"; else if (month == 04 && day == 17 && year == 2017) holString = "Easter Monday"; else if (month == 05 && day == 22 && year == 2017) holString = "Victoria Day"; else if (month == 07 && day == 01 && year == 2017) holString = "Canada Day"; else if (month == 08 && day == 07 && year == 2017) holString = "BC Day"; else if (month == 09 && day == 04 && year == 2017) holString = "Labour Day"; else if (month == 10 && day == 09 && year == 2017) holString = "Thanksgiving"; else if (month == 11 && day == 11 && year == 2017) holString = "Remembrance"; else if (month == 12 && day == 25 && year == 2017) holString = "Christmas"; else if (month == 12 && day == 26 && year == 2017) holString = "Boxing Day"; else if (month == 01 && day == 01 && year == 2018) holString = "New Years Day"; return holString; } function my_alt_holiday(day, month, year) { var aday, amonth; var holString = ""; // calculate alternate date from given Gregorian date var altDate = my_date(day, month, year); var altMonthYear = altDate.substring(altDate.indexOf(' ')+1, altDate.length); aday = eval(altDate.substring(0, altDate.indexOf(' '))); amonth = eval(altMonthYear.substring(0, altMonthYear.indexOf(' '))); if (aday == 1 ) { holString = "Happy " + altMonthNames[amonth]; } return holString; }