Cleaned-up docs
Tests for ZA and AU
This commit is contained in:
parent
59f5d2e91c
commit
b6968ccdb3
9 changed files with 76 additions and 111 deletions
85
data/SYNTAX
Normal file
85
data/SYNTAX
Normal file
|
@ -0,0 +1,85 @@
|
|||
== Holiday Gem Definition Syntax
|
||||
|
||||
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).
|
||||
|
||||
For example, the following holiday is on the first of January and available in the <tt>ca</tt>, <tt>us</tt> and <tt>au</tt> regions.
|
||||
|
||||
1:
|
||||
- name: New Year's Day
|
||||
regions: [ca, us, au]
|
||||
mday: 1
|
||||
|
||||
===== Dates defined by a week number (e.g. first Monday of a month)
|
||||
|
||||
[<tt>wday</tt>] Integer representing day of the week (0 = Sunday through 6 = Saturday).
|
||||
[<tt>week</tt>] Integer representing week number (1 = first week, 3 = third week, -1 = last week),
|
||||
|
||||
|
||||
For example, the following holiday is on the first Monday of September and available in the <tt>ca</tt> region.
|
||||
|
||||
9:
|
||||
- name: Labour Day
|
||||
regions: [ca]
|
||||
week: 1
|
||||
wday: 1
|
||||
|
||||
=== Calculating dates with methods
|
||||
|
||||
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: ca_victoria_day(year)
|
||||
|
||||
If a holiday can occur in different months (e.g. Easter) it can go in the '0' month.
|
||||
|
||||
0:
|
||||
- name: Easter Monday
|
||||
regions: [ca]
|
||||
function: easter(year)+1
|
||||
|
||||
Calculated-date functions take the year (integer) as a parameter and must return either a Date object or an integer representing the day of the month.
|
||||
|
||||
|
||||
=== Calculating observed dates
|
||||
|
||||
Several built-in methods are available for holidays that are observed on varying dates. For example, for a holiday that is observed on Monday if it falls on a weekend you could write:
|
||||
|
||||
7:
|
||||
- name: Canada Day
|
||||
regions: [ca]
|
||||
mday: 1
|
||||
observed: to_monday_if_weekend(date)
|
||||
|
||||
Observed-date functions take a Date object as a parameter and must return either a Date object or an integer representing the day of the month.
|
||||
|
||||
|
||||
|
38
data/au.yaml
38
data/au.yaml
|
@ -1,6 +1,10 @@
|
|||
# Australian holiday definitions for the Ruby Holiday gem.
|
||||
# Updated: 2008-11-21.
|
||||
# Source: http://en.wikipedia.org/wiki/Australian_public_holidays
|
||||
# Updated: 2008-11-29.
|
||||
# Sources:
|
||||
# - http://en.wikipedia.org/wiki/Australian_public_holidays
|
||||
# - http://www.docep.wa.gov.au/lr/LabourRelations/Content/Wages%20and%20Conditions/Public%20Holidays/Public_Holidays.html
|
||||
# - http://www.wst.tas.gov.au/employment_info/public_holidays
|
||||
# TODO: missing some regional holidays
|
||||
---
|
||||
months:
|
||||
0:
|
||||
|
@ -28,8 +32,12 @@ months:
|
|||
regions: [au_wa]
|
||||
week: 1
|
||||
wday: 1
|
||||
- name: Eight Hours Day
|
||||
regions: [au_tas]
|
||||
week: 2
|
||||
wday: 1
|
||||
- name: Labour Day
|
||||
regions: [au_vic, au_tas]
|
||||
regions: [au_vic]
|
||||
week: 2
|
||||
wday: 1
|
||||
4:
|
||||
|
@ -38,12 +46,20 @@ months:
|
|||
mday: 25
|
||||
5:
|
||||
- name: Labour Day
|
||||
regions: [au_qld, au_nt]
|
||||
regions: [au_qld]
|
||||
week: 1
|
||||
wday: 1
|
||||
- name: May Day
|
||||
regions: [au_nt]
|
||||
week: 1
|
||||
wday: 1
|
||||
6:
|
||||
- name: Foundation Day
|
||||
regions: [au_wa]
|
||||
week: 1
|
||||
wday: 1
|
||||
- name: Queen's Birthday
|
||||
regions: [au]
|
||||
regions: [au_act, au_nsw, au_sa, au_tas, au_nt, au_qld, au_vic]
|
||||
week: 2
|
||||
wday: 1
|
||||
- name: Queensland Day
|
||||
|
@ -62,15 +78,3 @@ months:
|
|||
- name: Boxing Day
|
||||
regions: [au]
|
||||
mday: 26
|
||||
methods:
|
||||
ca_victoria_day: |
|
||||
# Monday on or before May 24
|
||||
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
|
|
@ -1,17 +0,0 @@
|
|||
# Christian holiday definitions for the Ruby Holiday gem.
|
||||
# Updated 2008-11-21.
|
||||
---
|
||||
0:
|
||||
- name: Easter Sunday
|
||||
regions: [christian]
|
||||
function: easter(year) }
|
||||
- name: Palm Sunday
|
||||
regions: [christian]
|
||||
function: easter(year)-7 }
|
||||
- name: Good Friday
|
||||
regions: [christian]
|
||||
function: easter(year)-2 }
|
||||
12:
|
||||
- name: Christmas Day
|
||||
regions: [christian]
|
||||
mday: 25
|
14
data/za.yaml
14
data/za.yaml
|
@ -1,6 +1,6 @@
|
|||
# South African holiday definitions for the Ruby Holiday gem.
|
||||
#
|
||||
# Updated: 2008-11-22.
|
||||
# Updated: 2008-11-29.
|
||||
# Sources:
|
||||
# - http://en.wikipedia.org/wiki/Public_holidays_in_South_Africa
|
||||
# - http://www.info.gov.za/aboutsa/holidays.htm
|
||||
|
@ -17,38 +17,48 @@ months:
|
|||
- name: New Year's Day
|
||||
regions: [za]
|
||||
mday: 1
|
||||
observed: to_monday_if_sunday
|
||||
3:
|
||||
- name: Human Rights Day
|
||||
regions: [za]
|
||||
mday: 21
|
||||
observed: to_monday_if_sunday
|
||||
4:
|
||||
- name: Freedom Day
|
||||
regions: [za]
|
||||
mday: 27
|
||||
observed: to_monday_if_sunday
|
||||
5:
|
||||
- name: Workers' Day
|
||||
- name: Workers Day
|
||||
regions: [za]
|
||||
mday: 1
|
||||
observed: to_monday_if_sunday
|
||||
6:
|
||||
- name: Youth Day
|
||||
regions: [za]
|
||||
mday: 16
|
||||
observed: to_monday_if_sunday
|
||||
8:
|
||||
- name: National Women's Day
|
||||
regions: [za]
|
||||
mday: 9
|
||||
observed: to_monday_if_sunday
|
||||
9:
|
||||
- name: Heritage Day
|
||||
regions: [za]
|
||||
mday: 24
|
||||
observed: to_monday_if_sunday
|
||||
12:
|
||||
- name: Day of Reconciliation
|
||||
regions: [za]
|
||||
mday: 16
|
||||
observed: to_monday_if_sunday
|
||||
- name: Christmas Day
|
||||
regions: [za]
|
||||
mday: 25
|
||||
observed: to_monday_if_sunday
|
||||
- name: Day of Goodwill
|
||||
regions: [za]
|
||||
mday: 26
|
||||
observed: to_weekday_if_boxing_weekend
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue