Free JavaScript Event Calendar
Holidays & Alternate Dates
Home
History/Background
My Enhancements
View Demos
Calendar Gallery
How It Works
Using Enhancements
Customizing Look
Contrib
Holidays & Alternate Dates
Easier Event Editing
Frequently Asked Questions
Downloads
Contact Me
Sample Calendar With Moon Phase
Sample Calendar With Moon Phase as Alternate Date
Holidays
 
In Kevin Ilsen's original calendar you would enter holidays like any other event; however, you might choose to use a separate holiday "event" script file for easier maintenance. As an alternative approach, I added "holiday(day, month, year)" and "getAltHoly(day, month, year)" function calls which take as input the given Gregorian date and return any appropriate corresponding holiday text wrapped by format tags defined for "HolidayFormat" and "AltHolyFormat", respectively. Note: Since these holiday text strings are not events, they will not be included when using my Export Events enhancement.
 
If you have the appropriate additional JavaScript functions, set "showHolidays = true" and/or "showAltHoly = true" to enable them and remember to source the additional scripts defining these functions in your HTML pages to avoid calendar display errors. If the holiday functions you provide have different names or parameters, you may need to create "mapping" functions to translate my "holiday(day, month, year)" and/or "getAltHoly(day, month, year)" function calls to the appropriate functions you provide. This is also shown in the sample on the Downloads page.
 
For holidays, one of the sample calendars includes a script for automatically including most of the holidays typically found on calendars in the United States based on JavaScript date functions by Martin Webb (tech.irt.org/articles/script.htm). Most holidays are usually specified as either occurring on a specific date (such as January 1st) or on the nth weekday of a month (such as last Monday in May) and that script can do both. For holidays in other countries it should be possible to modify the script accordingly.

TIP

You can embed HTML tags in the holiday return text for formatting or to include images or hyperlinks.

TIP

While Events are tied to the particular date entered, Holidays, being rule-based, are more flexible and can be tied to a date, or a weekday, or a combination of the two. Unlike Events; however, Holidays cannot currently be exported.

If you have regularly repeating events you could define them as "alternate holidays" by defining a function like the following and setting "showAltHoly = true", but you'd also have to add logic for any exceptions as well.

function getAltHoly(day, month, year) {
     if (month==6 && year==2004) {
             return; // skip this particular month
     } else if (day == NthDay(third, fri, month, year)) {
             return "3rd Friday of month";
     }
}

Firefighters Calendar Example
Firefighters Calendar With 3 Day Cycle

Alternate Dates
 
Besides the Gregorian calendar, there are other calendar systems in use around the world (i.e. the Hebrew, Moslem, Indian, and Chinese calendars). Some sites would like to display the corresponding date from an alternate calendar system along with the Gregorian date or phases of the moon (such as in the example at the top of this page). Another use of an alternate date is a cyclic calendar such as a Fire Department which uses 24 hour shifts every 3rd day (A-B-C or Gold-Red-Black). By introducing a function which subtracts the date from a known base date and then uses the modulus function to calculate a remainder, you can display some alternate date text appropriate to each day of the desired cycle.
 
In Kevin Ilsen's original calendar, you would have to do this by defining the alternate date as you would any other event (although you may choose to use a separate "altdate" event script file for easier maintenance). To provide another approach, I added the capability to retrieve alternate date text from an additional, user-supplied JavaScript and display it along with the Gregorian date. If you have the necessary JavaScript functions defined, set "showAltDate = true", and provide a "getAltDate(day, month, year)" function which returns the alternate date text for the given Gregorian date and a "getAltMonth(first, month, year, last)" function which returns the alternate date text for the given Gregorian time period. The alternate date text returned is wrapped by any format tags defined by "AltDateFormat" and "AltMonthFormat". Note that these alternate dates will not be included if you enable the Export Event enhancement.
 
If the date functions you use have different names or arguments, you may need to have a "mapping" function in between. For example, for my definition of the "getAltDate(day, month, year)" function I might call a "myDate(day, month, year, DayStyle)" function while for my definition of "getAltMonth(first, month, year, last)" I might return the results from calling "myDate(first, month, year, MonthStyle)" and "myDate(last, month, year, MonthStyle)" separated by a hyphen. Remember to source the scripts which define these functions in your HTML pages to avoid problems with your calendar display.
 
This is not as complicated as it sounds; check out Sample 2 on the Demos page and the corresponding files in the Downloads package.
 
 
Compatible Date and Holiday Functions
 
I have adapted three alternate date JavaScripts for use with my calendar. One is a Hebrew date script (illustrated below) from kaluach.net which calculates Hebrew dates as well as Jewish and secular holidays. The second is a Hebrew date script by Bill Hastings (found at shamash.org) which calculates Hebrew dates but not holidays. The last is a moon phase script (illustrated above) originally written by James Thiele (www.eskimo.com/~jet/javascript). I do not include my modified versions of these scripts in my download packages here because I do not have permission from their authors to do so, but if you show me that you have permission to use them, I can send you my modified versions. The cyclic A-B-C script is included with the samples.

For holidays, one of the sample calendars includes a script for automatically including most of the holidays typically found on calendars in the United States based on JavaScript date functions by Martin Webb (tech.irt.org/articles/script.htm). The included holidays are specified as either occurring on a specific date (such as January 1st) or on the nth weekday of a month (such as last Monday in May). For holidays in other countries it should be possible to modify the script accordingly.
 
If you are aware of any other scripts for calculating holidays or corresponding dates in other calendar systems from Gregorian dates, please contact me so I can include them on the User Contributions page. If an alternate date script is not available, one could always define an array containing the corresponding Gregorian dates for the first day of each alternate calendar month and then interpolate to determine the alternate date for a given Gregorian date. One of the sample calendars included in the package on the Downloads page illustrates how to do this.

Sample Calendar With Hebrew Date
Sample Calendar With Hebrew Date as Alternate Date

For those who prefer to use the event approach for Hebrew dates and/or holidays, Michael J. Radwin's hebcal.com website (which uses Danny Sadinoff's Hebcal program) will actually generate and download a "DefineEvent" script file named "hebcal.js" if you add "&cfg=e" to the URL of the page you get when you press the getCalendar button. Alternatively, he gives instructions here for linking your calendar page to his site for the events. You can also use a combination approach with holidays as events, but the alternate dates calculated as an attribute.

If you like our script, please rate it!

 

Last updated on