Skip to content

Commit

Permalink
Merge pull request #79 from ppeble/issue-24
Browse files Browse the repository at this point in the history
Issue-24: add tests to ensure coverage on all methods
  • Loading branch information
ppeble authored Sep 30, 2018
2 parents a1d3c41 + 90402fa commit 814026a
Show file tree
Hide file tree
Showing 33 changed files with 396 additions and 158 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Holiday definitions

## 3.0.0

Major semver bump as the format for custom methods has been changed to complete [issue-24](https://github.com/holidays/definitions/issues/24). Downstream consumers will need to update to be able to parse them. However there are **no behavior changes** with this update.

In summary: we have switched to language-specific custom methods. Instead of a plain `source` field you will need a specific language implementation, e.g. `ruby`, `golang`, etc.

Currently we only have `ruby` but we can now expand these definitions for use in other languages. Please see the [custom methods ADR](doc/architecture/adr-001.md) for more in-depth information on why this change was made.

You can also view the updated ['Methods' section in the SYNTAX doc](doc/SYNTAX.md#methods) for more info and examples.

## 2.5.3

* Add missing `observed` logic for 'St. Patricks Day' in `gb_nir`
Expand Down
26 changes: 26 additions & 0 deletions METHODS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
methods:
easter:
arguments: year
orthodox_easter:
arguments: year
orthodox_easter_julian:
arguments: year
to_monday_if_sunday:
arguments: date
to_monday_if_weekend:
arguments: date
to_weekday_if_boxing_weekend:
arguments: date
to_weekday_if_boxing_weekend_from_year:
arguments: year
to_weekday_if_weekend:
arguments: date
calculate_day_of_month:
arguments: year, month, day, wday
to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday:
arguments: year
to_tuesday_if_sunday_or_monday_if_saturday:
arguments: date
lunar_to_solar:
arguments: year, month, day, region
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ Currently it is only used by the [existing Holidays gem](https://github.com/holi
definitions and generates ruby classes for use in that gem. In the future it will be used by other languages in
a similar manner.

*Please note* that this is *not* a gem. The validation process is written in ruby simply for convenience. The real
**Please note** that this is _not_ a gem. The validation process is written in ruby simply for convenience. The real
stars of this show are the YAML files.

### Syntax
### Documentation

The definition syntax is a custom format developed over the life of this project. Please see
[our syntax doc](SYNTAX.md) for more information on how to format definitions.

### How to contribute

See our [contribution guidelines](CONTRIBUTING.md) for information on how to help out!
1. [Syntax Guide](doc/SYNTAX.md)
2. [Contribution Guidelines](doc/CONTRIBUTING.md)
3. [Maintainer Guidelines](doc/MAINTAINERS.md)
4. [Architecture Decision Records](doc/architecture/README.md)

### Credits

Expand Down
1 change: 1 addition & 0 deletions ar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ months:
- name: Navidad
regions: [ar]
mday: 25

tests:
- given:
date: '2016-01-01'
Expand Down
9 changes: 6 additions & 3 deletions at.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ months:
- name: 2. Weihnachtstag
regions: [at]
mday: 26

tests:
- given:
date: '2009-01-01'
Expand All @@ -67,19 +68,16 @@ tests:
- given:
date: '2009-04-13'
regions: ['at']
options: 'informal'
expect:
name: 'Ostermontag'
- given:
date: '2009-05-21'
regions: ['at']
options: 'informal'
expect:
name: 'Christi Himmelfahrt'
- given:
date: '2009-06-01'
regions: ['at']
options: 'informal'
expect:
name: 'Pfingstmontag'
- given:
Expand Down Expand Up @@ -111,3 +109,8 @@ tests:
regions: ['at']
expect:
holiday: false
- given:
date: '2017-06-15'
regions: ['at']
expect:
name: "Fronleichnam"
45 changes: 35 additions & 10 deletions au.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Australian holiday definitions for the Ruby Holiday gem.
# Updated: 2008-11-29.
# Updated: 2018-08-30
# 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
Expand Down Expand Up @@ -178,7 +178,7 @@ months:
methods:
afl_grand_final:
arguments: year
source: |
ruby: |
case year
when 2015
Date.civil(2015, 10, 2)
Expand All @@ -192,7 +192,7 @@ methods:
# celebrated twice in 2012
# in october again from 2016
arguments: year
source: |
ruby: |
if year >= 2016
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
elsif year == 2012
Expand All @@ -204,44 +204,44 @@ methods:
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
# in june until 2015
arguments: year
source: |
ruby: |
if year <= 2015
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 6, 2, 1)
end
qld_labour_day_may:
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
# for 2013 to 2016 it was in October, otherwise it's in May
arguments: year
source: |
ruby: |
if year < 2013 || year >= 2016
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, 1, 1)
end
qld_labour_day_october:
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
# for 2013 to 2016 it was in October, otherwise it's in May
arguments: year
source: |
ruby: |
if year >= 2013 && year < 2016
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 1, 1)
end
g20_day_2014_only:
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
# G20 day in brisbane, in 2014, on november 14
arguments: year
source: |
ruby: |
year == 2014 ? 14 : nil
hobart_show_day:
# http://worksafe.tas.gov.au/__data/assets/pdf_file/0008/287036/Public_Holidays_2014.pdf
# The Thursday before the fourth Saturday in October.
arguments: year
source: |
ruby: |
fourth_sat_in_oct = Date.civil(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 4, :saturday))
fourth_sat_in_oct - 2 # the thursday before
march_pub_hol_sa:
# http://www.safework.sa.gov.au/show_page.jsp?id=2483#.VQ9Mfmb8-8E
# The Holidays Act 1910 provides for the third Monday in May to be a public holiday. Since 2006 this public holiday has been observed on the second Monday in March through the issuing of a special Proclamation by the Governor.
arguments: year
source: |
ruby: |
if year < 2006
nil
else
Expand All @@ -251,14 +251,29 @@ methods:
# http://www.safework.sa.gov.au/show_page.jsp?id=2483#.VQ9Mfmb8-8E
# The Holidays Act 1910 provides for the third Monday in May to be a public holiday. Since 2006 this public holiday has been observed on the second Monday in March through the issuing of a special Proclamation by the Governor.
arguments: year
source: |
ruby: |
if year >= 2006
nil
else
Date.civil(year, 5, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, :third, :monday))
end
tests:
- given:
date: "2017-04-14"
regions: ["au"]
expect:
name: "Good Friday"
- given:
date: "2017-04-15"
regions: ["au_nsw"]
expect:
name: "Easter Saturday"
- given:
date: ['2010-4-4', "2017-04-16"]
regions: ["au_nsw"]
expect:
name: "Easter Sunday"
- given:
date: '2013-10-07'
regions: ["au_qld"]
Expand Down Expand Up @@ -713,8 +728,18 @@ tests:
regions: ["au_tas"]
expect:
name: "New Year's Day"
- given:
date: '2016-03-27'
regions: ["au_qld"]
expect:
holiday: false
- given:
date: '2017-04-16'
regions: ["au_qld"]
expect:
name: "Easter Sunday"
- given:
date: "2014-11-14"
regions: ["au_qld_brisbane"]
expect:
name: "G20 Day"
25 changes: 25 additions & 0 deletions be_fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,28 @@ tests:
options: ["informal"]
expect:
name: 'Noël'
- given:
date: '2017-4-16'
regions: ['be_fr']
expect:
name: 'Pâques'
- given:
date: '2017-4-17'
regions: ['be_fr']
expect:
name: 'Lundi de Pâques'
- given:
date: '2017-5-25'
regions: ['be_fr']
expect:
name: 'Ascension'
- given:
date: '2017-6-4'
regions: ['be_fr']
expect:
name: 'Pentecôte'
- given:
date: '2017-6-5'
regions: ['be_fr']
expect:
name: 'Lundi de Pentecôte'
25 changes: 25 additions & 0 deletions be_nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,28 @@ tests:
options: ["informal"]
expect:
name: 'Kerstmis'
- given:
date: '2017-4-16'
regions: ['be_nl']
expect:
name: 'Pasen'
- given:
date: '2017-4-17'
regions: ['be_nl']
expect:
name: 'Paasmaandag'
- given:
date: '2017-5-25'
regions: ['be_nl']
expect:
name: 'O.H. Hemelvaart'
- given:
date: '2017-6-4'
regions: ['be_nl']
expect:
name: 'Pinksteren'
- given:
date: '2017-6-5'
regions: ['be_nl']
expect:
name: 'Pinkstermaandag'
5 changes: 3 additions & 2 deletions ca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ months:
regions: [ca_yt]
mday: 21
year_ranges:
- after: 2017
- after: 2017
7:
- name: Canada Day
regions: [ca]
Expand Down Expand Up @@ -184,11 +184,12 @@ months:
mday: 26
observed: to_weekday_if_boxing_weekend(date)
type: informal

methods:
ca_victoria_day:
# Monday on or before May 24
arguments: year
source: |
ruby: |
date = Date.civil(year,5,24)
if date.wday > 1
date -= (date.wday - 1)
Expand Down
7 changes: 4 additions & 3 deletions ch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ months:
- name: Restauration de la République
regions: [ch_ge]
mday: 31

methods:
ch_vd_lundi_du_jeune_federal:
# Monday after the third Sunday of September
arguments: year
source: |
ruby: |
date = Date.civil(year,9,1)
# Find the first Sunday of September
until date.wday.eql? 0 do
Expand All @@ -141,7 +142,7 @@ methods:
ch_ge_jeune_genevois:
# Thursday after the first Sunday of September
arguments: year
source: |
ruby: |
date = Date.civil(year,9,1)
# Find the first Sunday of September
until date.wday.eql? 0 do
Expand All @@ -152,7 +153,7 @@ methods:
ch_gl_naefelser_fahrt:
# First Thursday of April. If the first Thursday of April is in the week before easter, then a week later.
arguments: year
source: |
ruby: |
date = Date.civil(year,4,1)
# Find the first Thursday of April
until date.wday.eql? 4 do
Expand Down
Loading

0 comments on commit 814026a

Please sign in to comment.