Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'samzurcher/master'
- Loading branch information
Showing
6 changed files
with
440 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,187 @@ | |||
# Swiss holiday definitions for the Ruby Holiday gem. | |||
# | |||
# Updated: 2012-03-16. | |||
# Sources: | |||
# http://www.bj.admin.ch/content/dam/data/staat_buerger/zivilprozessrecht/kant-feiertage.pdf | |||
# | |||
# Word of warning: | |||
# ================ | |||
# As the holidays are defined on a state level and sometimes even on a district / village level, | |||
# this holiday definition is an approximation of the reality. It should be accurate for most of the cases but | |||
# no guarantee is given that it is correct for all the special cases :-). | |||
# Considers both official holidays and holidays that are handled as if they were official holidays. | |||
# | |||
# Holiday names are in German in case they are celebrated in the German speaking area and in French / Italian otherwise. | |||
# | |||
# Known Issues: | |||
# * ch_ur: 26th of December is not celebrated in case the 25th is a Monday or a Friday. | |||
# * ch_fr: Fronleichnam, Maria Himmelfahrt, Allerheiligen, Maria Empfaengnis is celebrated in all villages except | |||
# some villages of the district of See. | |||
# * ch_so: - There are a lot of village holidays not included here. | |||
# - 1st of May is holiday only starting at noon; not included here. | |||
# - 19th of March is celebrated only in a couple of villages | |||
# * ch_ar: 26th of December is not celebrated in case the 25th is a Monday or a Friday. | |||
# * ch_ai: - 22nd of September is celebrated only in part of the state. | |||
# - 26th of December is not celebrated in case the 25th is a Monday or a Friday. | |||
# * ch_ne: 26th of December and 2nd of January are only celebrated in case 25th of December and 1st of January are Sundays | |||
# | |||
# | |||
# | |||
# all regions [ch_zh, ch_be, ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_bs, ch_bl, | |||
# ch_sh, ch_ar, ch_ai, ch_sg, ch_gr, ch_ag, ch_tg, ch_ti, ch_vd, ch_vs, ch_ne, ch_ge, ch_ju] | |||
# | |||
--- | |||
months: | |||
0: | |||
- name: Karfreitag | |||
regions: [ch_zh, ch_be, ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_bs, ch_bl, ch_sh, ch_ar, ch_ai, ch_sg, ch_gr, ch_ag, ch_tg, ch_ti, ch_vd, ch_ne, ch_ge, ch_ju] | |||
function: easter(year)-2 | |||
- name: Ostermontag | |||
regions: [ch_zh, ch_be, ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_bs, ch_bl, ch_sh, ch_ar, ch_ai, ch_sg, ch_gr, ch_ag, ch_tg, ch_ti, ch_vd, ch_vs, ch_ge, ch_ju] | |||
function: easter(year)+1 | |||
# State holiday but observed in all the states | |||
- name: Auffahrt | |||
regions: [ch] | |||
function: easter(year)+39 | |||
- name: Pfingstmontag | |||
regions: [ch_zh, ch_be, ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_bs, ch_bl, ch_sh, ch_ar, ch_ai, ch_sg, ch_gr, ch_ag, ch_tg, ch_ti, ch_vd, ch_vs, ch_ge, ch_ju] | |||
function: easter(year)+50 | |||
- name: Fronleichnam | |||
regions: [ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_zg, ch_fr, ch_so, ch_ai, ch_ag, ch_ti, ch_vs, ch_ne, ch_ju] | |||
function: easter(year)+60 | |||
- name: Lundi du Jeûne fédéral | |||
regions: [ch_vd] | |||
function: ch_vd_lundi_du_jeune_federal(year) | |||
- name: Jeûne genevoi | |||
regions: [ch_ge] | |||
function: ch_ge_jeune_genevoi(year) | |||
1: | |||
- name: Neujahrstag | |||
regions: [ch_zh, ch_be, ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_bs, ch_bl, ch_sh, ch_ar, ch_ai, ch_sg, ch_gr, ch_ag, ch_tg, ch_vd, ch_vs, ch_ne, ch_ge, ch_ju] | |||
mday: 1 | |||
- name: Berchtoldstag | |||
regions: [ch_zh, ch_be, ch_lu, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_sh, ch_sg, ch_ag, ch_tg, ch_vd, ch_vs, ch_ne, ch_ju] | |||
mday: 2 | |||
- name: Dreikönigstag | |||
regions: [ch_ur, ch_sz, ch_ti] | |||
mday: 6 | |||
3: | |||
- name: Instauration de la République | |||
regions: [ch_ne] | |||
mday: 1 | |||
- name: Josephstag | |||
regions: [ch_ur, ch_sz, ch_nw, ch_ti, ch_vs] | |||
mday: 19 | |||
4: | |||
- name: Näfelser Fahrt | |||
regions: [ch_gl] | |||
function: ch_gl_naefelser_fahrt(year) | |||
5: | |||
- name: Tag der Arbeit | |||
regions: [ch_zh, ch_bs, ch_bl, ch_sh, ch_ag, ch_tg, ch_ti, ch_ne, ch_ju] | |||
mday: 1 | |||
6: | |||
- name: Commémoration du plébiscite jurassien | |||
regions: [ch_ju] | |||
mday: 23 | |||
- name: San Pietro e Paolo | |||
regions: [ch_ti] | |||
mday: 29 | |||
8: | |||
# Federal holiday | |||
- name: Bundesfeiertag | |||
regions: [ch] | |||
mday: 1 | |||
- name: Mariä Himmelfahrt | |||
regions: [ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_zg, ch_fr, ch_so, ch_ai, ch_ag, ch_ti, ch_vs, ch_ju] | |||
mday: 15 | |||
9: | |||
- name: Mauritiustag | |||
regions: [ch_ai] | |||
mday: 22 | |||
- name: Bruderklausenfest | |||
regions: [ch_ow] | |||
mday: 25 | |||
11: | |||
- name: Allerheiligen | |||
regions: [ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_ai, ch_sg, ch_ag, ch_ti, ch_vs, ch_ju] | |||
mday: 1 | |||
12: | |||
- name: Maria Empfängnis | |||
regions: [ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_zg, ch_fr, ch_ai, ch_ag, ch_ti, ch_vs] | |||
mday: 8 | |||
# State holiday but observed in all the states | |||
- name: Weihnachten | |||
regions: [ch] | |||
mday: 25 | |||
- name: Stefanstag | |||
regions: [ch_zh, ch_be, ch_lu, ch_ur, ch_sz, ch_ow, ch_nw, ch_gl, ch_zg, ch_fr, ch_so, ch_bs, ch_bl, ch_sh, ch_ar, ch_ai, ch_sg, ch_gr, ch_ag, ch_tg, ch_ti, ch_vs, ch_ne] | |||
mday: 26 | |||
- 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 | |||
def self.ch_vd_lundi_du_jeune_federal(year) | |||
date = Date.civil(year,9,1) | |||
# Find the first Sunday of September | |||
until date.wday.eql? 0 do | |||
date += 1 | |||
end | |||
# There are 15 days between the first Sunday | |||
# and the Monday after the third Sunday | |||
date + 15 | |||
end | |||
ch_ge_jeune_genevoi: | | |||
# Thursday after the first Sunday of September | |||
def self.ch_ge_jeune_genevoi(year) | |||
date = Date.civil(year,9,1) | |||
# Find the first Sunday of September | |||
until date.wday.eql? 0 do | |||
date += 1 | |||
end | |||
# Thursday is four days after Sunday | |||
date + 4 | |||
end | |||
ch_gl_naefelser_fahrt: | | |||
# First Thursday of April. If the first Thursday of April is in the week before easter, then a week later. | |||
def self.ch_gl_naefelser_fahrt(year) | |||
date = Date.civil(year,4,1) | |||
# Find the first Thursday of April | |||
until date.wday.eql? 4 do | |||
date += 1 | |||
end | |||
if date.eql?(easter(year)-3) | |||
date += 7 | |||
end | |||
date | |||
end | |||
tests: | | |||
{ Date.civil(2012,8,1) => 'Bundesfeiertag', | |||
Date.civil(2012,12,25) => 'Weihnachten', | |||
Date.civil(2012,05,17) => 'Auffahrt' | |||
}.each do |date, name| | |||
assert_equal name, (Holidays.on(date, :ch)[0] || {})[:name] | |||
end | |||
{ Date.civil(2012,8,1) => 'Bundesfeiertag', | |||
Date.civil(2012,12,25) => 'Weihnachten', | |||
Date.civil(2012,05,17) => 'Auffahrt', | |||
Date.civil(2012,5,1) => 'Tag der Arbeit', | |||
Date.civil(2012,12,26) => 'Stefanstag' | |||
}.each do |date, name| | |||
assert_equal name, (Holidays.on(date, :ch_zh)[0] || {})[:name] | |||
end | |||
[Date.civil(2012,9,17), Date.civil(2013,9,16), Date.civil(2014,9,22)].each do |date| | |||
assert_equal 'Lundi du Jeûne fédéral', (Holidays.on(date, :ch_vd)[0] || {})[:name] | |||
end | |||
[Date.civil(2012,9,6), Date.civil(2013,9,5), Date.civil(2014,9,11)].each do |date| | |||
assert_equal 'Jeûne genevoi', (Holidays.on(date, :ch_ge)[0] || {})[:name] | |||
end | |||
[Date.civil(2012,4,12), Date.civil(2013,4,4), Date.civil(2014,4,3)].each do |date| | |||
assert_equal 'Näfelser Fahrt', (Holidays.on(date, :ch_gl)[0] || {})[:name] | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,92 @@ | |||
# encoding: utf-8 | |||
module Holidays | |||
# This file is generated by the Ruby Holidays gem. | |||
# | |||
# Definitions loaded: data/ch.yaml | |||
# | |||
# To use the definitions in this file, load it right after you load the | |||
# Holiday gem: | |||
# | |||
# require 'holidays' | |||
# require 'holidays/ch' | |||
# | |||
# All the definitions are available at https://github.com/alexdunae/holidays | |||
module CH # :nodoc: | |||
def self.defined_regions | |||
[:ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju, :ch_vs, :ch] | |||
end | |||
|
|||
def self.holidays_by_month | |||
{ | |||
0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Karfreitag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju]}, | |||
{:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :name => "Ostermontag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_vs, :ch_ge, :ch_ju]}, | |||
{:function => lambda { |year| Holidays.easter(year)+39 }, :function_id => "easter(year)+39", :name => "Auffahrt", :regions => [:ch]}, | |||
{:function => lambda { |year| Holidays.easter(year)+50 }, :function_id => "easter(year)+50", :name => "Pfingstmontag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_vs, :ch_ge, :ch_ju]}, | |||
{:function => lambda { |year| Holidays.easter(year)+60 }, :function_id => "easter(year)+60", :name => "Fronleichnam", :regions => [:ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_zg, :ch_fr, :ch_so, :ch_ai, :ch_ag, :ch_ti, :ch_vs, :ch_ne, :ch_ju]}, | |||
{:function => lambda { |year| Holidays.ch_vd_lundi_du_jeune_federal(year) }, :function_id => "ch_vd_lundi_du_jeune_federal(year)", :name => "Lundi du Jeûne fédéral", :regions => [:ch_vd]}, | |||
{:function => lambda { |year| Holidays.ch_ge_jeune_genevoi(year) }, :function_id => "ch_ge_jeune_genevoi(year)", :name => "Jeûne genevoi", :regions => [:ch_ge]}], | |||
1 => [{:mday => 1, :name => "Neujahrstag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_vd, :ch_vs, :ch_ne, :ch_ge, :ch_ju]}, | |||
{:mday => 2, :name => "Berchtoldstag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_sh, :ch_sg, :ch_ag, :ch_tg, :ch_vd, :ch_vs, :ch_ne, :ch_ju]}, | |||
{:mday => 6, :name => "Dreikönigstag", :regions => [:ch_ur, :ch_sz, :ch_ti]}], | |||
3 => [{:mday => 1, :name => "Instauration de la République", :regions => [:ch_ne]}, | |||
{:mday => 19, :name => "Josephstag", :regions => [:ch_ur, :ch_sz, :ch_nw, :ch_ti, :ch_vs]}], | |||
4 => [{:function => lambda { |year| Holidays.ch_gl_naefelser_fahrt(year) }, :function_id => "ch_gl_naefelser_fahrt(year)", :name => "Näfelser Fahrt", :regions => [:ch_gl]}], | |||
5 => [{:mday => 1, :name => "Tag der Arbeit", :regions => [:ch_zh, :ch_bs, :ch_bl, :ch_sh, :ch_ag, :ch_tg, :ch_ti, :ch_ne, :ch_ju]}], | |||
6 => [{:mday => 23, :name => "Commémoration du plébiscite jurassien", :regions => [:ch_ju]}, | |||
{:mday => 29, :name => "San Pietro e Paolo", :regions => [:ch_ti]}], | |||
8 => [{:mday => 1, :name => "Bundesfeiertag", :regions => [:ch]}, | |||
{:mday => 15, :name => "Mariä Himmelfahrt", :regions => [:ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_zg, :ch_fr, :ch_so, :ch_ai, :ch_ag, :ch_ti, :ch_vs, :ch_ju]}], | |||
9 => [{:mday => 22, :name => "Mauritiustag", :regions => [:ch_ai]}, | |||
{:mday => 25, :name => "Bruderklausenfest", :regions => [:ch_ow]}], | |||
11 => [{:mday => 1, :name => "Allerheiligen", :regions => [:ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_ai, :ch_sg, :ch_ag, :ch_ti, :ch_vs, :ch_ju]}], | |||
12 => [{:mday => 8, :name => "Maria Empfängnis", :regions => [:ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_zg, :ch_fr, :ch_ai, :ch_ag, :ch_ti, :ch_vs]}, | |||
{:mday => 25, :name => "Weihnachten", :regions => [:ch]}, | |||
{:mday => 26, :name => "Stefanstag", :regions => [:ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vs, :ch_ne]}, | |||
{:mday => 31, :name => "Restauration de la République", :regions => [:ch_ge]}] | |||
} | |||
end | |||
end | |||
|
|||
# Monday after the third Sunday of September | |||
def self.ch_vd_lundi_du_jeune_federal(year) | |||
date = Date.civil(year,9,1) | |||
# Find the first Sunday of September | |||
until date.wday.eql? 0 do | |||
date += 1 | |||
end | |||
# There are 15 days between the first Sunday | |||
# and the Monday after the third Sunday | |||
date + 15 | |||
end | |||
|
|||
|
|||
# Thursday after the first Sunday of September | |||
def self.ch_ge_jeune_genevoi(year) | |||
date = Date.civil(year,9,1) | |||
# Find the first Sunday of September | |||
until date.wday.eql? 0 do | |||
date += 1 | |||
end | |||
# Thursday is four days after Sunday | |||
date + 4 | |||
end | |||
|
|||
|
|||
# First Thursday of April. If the first Thursday of April is in the week before easter, then a week later. | |||
def self.ch_gl_naefelser_fahrt(year) | |||
date = Date.civil(year,4,1) | |||
# Find the first Thursday of April | |||
until date.wday.eql? 4 do | |||
date += 1 | |||
end | |||
if date.eql?(easter(year)-3) | |||
date += 7 | |||
end | |||
date | |||
end | |||
|
|||
|
|||
|
|||
end | |||
|
|||
Holidays.merge_defs(Holidays::CH.defined_regions, Holidays::CH.holidays_by_month) |
Oops, something went wrong.