Definition files have two main parts: *months* and *methods*. Before you start, you may want to look some of the existing files at http://code.dunae.ca/svn/holidays/trunk/data.
=== Months
Holidays are grouped by month from 1 through 12. Each entry within a month can have several fields.
[<tt>name</tt>] The name of the holiday.
[<tt>regions</tt>] One or more region codes.
===== Dates defined by a fixed date (e.g. January 1st)
[<tt>wday</tt>] Integer representing day of the month (1 through 31).
In addition to defining holidays by day or week, you can create custom methods to calculate a date.
For example, Canada celebrates Victoria Day, which falls on the Monday on or before May 24. So, under the <tt>methods</tt> section we could create a custom method that returns a Date object.
methods:
ca_victoria_day: |
def self.ca_victoria_day(year)
date = Date.civil(year,5,24)
if date.wday > 1
date -= (date.wday - 1)
elsif date.wday == 0
date -= 6
end
date
end
This would be represented in the <tt>months</tt> section as:
5:
- name: Victoria Day
regions: [ca]
function: lambda { |year| ca_victoria_day(year) }
Functions called in this manner must return either a Date object or an integer representing the day of the month.