Skip to content

Commit

Permalink
Merge remote-tracking branch 'samzurcher/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdunae committed Mar 16, 2012
2 parents 402581f + fd8be4d commit 3c0c38f
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 41 deletions.
187 changes: 187 additions & 0 deletions data/ch.yaml
@@ -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
4 changes: 3 additions & 1 deletion data/index.yaml
Expand Up @@ -5,6 +5,7 @@ defs:
AU: ['au.yaml'] AU: ['au.yaml']
BR: ['br.yaml'] BR: ['br.yaml']
CA: ['ca.yaml', 'north_america_informal.yaml'] CA: ['ca.yaml', 'north_america_informal.yaml']
CH: ['ch.yaml']
CZ: ['cz.yaml'] CZ: ['cz.yaml']
DK: ['dk.yaml'] DK: ['dk.yaml']
DE: ['de.yaml'] DE: ['de.yaml']
Expand Down Expand Up @@ -32,5 +33,6 @@ defs:
ZA: ['za.yaml'] ZA: ['za.yaml']
North_America: ['ca.yaml', 'mx.yaml', 'us.yaml', 'north_america_informal.yaml'] North_America: ['ca.yaml', 'mx.yaml', 'us.yaml', 'north_america_informal.yaml']
Scandinavia: ['dk.yaml', 'is.yaml', 'no.yaml', 'se.yaml', 'fi.yaml'] Scandinavia: ['dk.yaml', 'is.yaml', 'no.yaml', 'se.yaml', 'fi.yaml']
Europe: ['at.yaml', 'cz.yaml', 'dk.yaml', 'de.yaml', 'el.yaml', 'es.yaml', 'fr.yaml', 'gb.yaml', 'hu.yaml', 'ie.yaml', 'is.yaml', 'it.yaml', 'li.yaml', 'nl.yaml', 'no.yaml', 'pl.yaml', 'pt.yaml'] Europe: ['at.yaml', 'ch.yaml', 'cz.yaml', 'dk.yaml', 'de.yaml', 'el.yaml', 'es.yaml', 'fr.yaml', 'gb.yaml', 'hu.yaml', 'ie.yaml', 'is.yaml', 'it.yaml', 'li.yaml', 'nl.yaml', 'no.yaml', 'pl.yaml', 'pt.yaml']
Europe: ['at.yaml', 'ch.yaml', 'cz.yaml', 'dk.yaml', 'de.yaml', 'el.yaml', 'es.yaml', 'fr.yaml', 'gb.yaml', 'hu.yaml', 'ie.yaml', 'is.yaml', 'it.yaml', 'li.yaml', 'nl.yaml', 'no.yaml', 'pl.yaml', 'pt.yaml']
JP: ['jp.yaml'] JP: ['jp.yaml']
92 changes: 92 additions & 0 deletions lib/holidays/ch.rb
@@ -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)

0 comments on commit 3c0c38f

Please sign in to comment.