Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Austria #1

Merged
merged 7 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 67 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,78 @@
# Feiertage
Feiertage is a Go/Golang library for calculating german bank holidays. It includes the calculation of the date of Easter and, more important, offers ways to retrieve the public holiday for a state of Germany (=Bundesland).
Feiertage is a Go/Golang library for calculating German and Austrianbank holidays. It includes the calculation of the date of Easter and, more importantly, offers ways to retrieve public holidays for a state of Germany or
Austria (=Bundesland).

The library is probably useful only for people realizing use cases with special "german" requirements. This might be shift schedules or capacity calculation.
The library is probably useful only for people realizing use cases with special "Germanic" requirements, such as shift schedules or capacity calculation.

### Documentation
See https://godoc.org/github.com/wlbr/feiertage

### Usage:
There are to types of functions:
There are two types of functions:

* `<feiertag>(year)` and
* `<feiertag>(year)` and
* `<region>(year optional:IncludingSundays:true)`

`<feiertag>` returns an extended `time` object (type `feiertag`). It carrys the concrete date plus the name of the holiday.
`<feiertag>` may be any of
`<feiertag>` returns an extended `time` object (type `feiertag`). It carries the date of the holiday
in the requested year plus the name of the holiday. `<feiertag>` may be any of the following:

||||
|----|-----|----|
`Neujahr` | `Epiphanias` | `HeiligeDreiKönige`
`Valentinstag` | `Weiberfastnacht` | `Karnevalssonntag`
`Rosenmontag` | `Fastnacht` | `Aschermittwoch`
`Palmsonntag` | `Gründonnerstag` | `Karfreitag`
`Ostern` | `BeginnSommerzeit` | `Ostermontag`
`Walpurgisnacht` | `TagDerArbeit` | `TagDerBefreiung`
`Muttertag` | `ChristiHimmelfahrt` | `Vatertag`
`Pfingsten` | `PfingstMontag` | `Dreifaltigkeitssonntag`
`Fronleichnam` | `MariäHimmelfahrt` | `TagDerDeutschenEinheit`
`Erntedankfest` | `Reformationstag` | `Halloween`
`BeginnWinterzeit` | `Allerheiligen` | `Allerseelen`
`Martinstag` | `Karnevalsbeginn` | `BußUndBettag`
`Thanksgiving` | `Blackfriday` | `Volkstrauertag`
`Nikolaus` | `MariäUnbefleckteEmpfängnis` | `Totensonntag`
`ErsterAdvent` | `ZweiterAdvent` | `DritterAdvent`
`VierterAdvent` | `Heiligabend` | `Weihnachten`
`ZweiterWeihnachten` | `Silvester` | &nbsp;

`<region>` returns an object of type `region`. It offers a list of public holidays valid in the referred state` | `the name and the shortname of the state as attributes.
`<region>` may be any of
`Neujahr` | `Epiphanias` | `HeiligeDreiKönige`
`Valentinstag` | `Josefitag` | `Weiberfastnacht`
`Karnevalssonntag` | `Rosenmontag` | `Fastnacht`
`Aschermittwoch` | `Palmsonntag` | `Gründonnerstag`
`Karfreitag` | `Ostern` | `BeginnSommerzeit`
`Ostermontag` | `Walpurgisnacht` | `TagDerArbeit`
`TagDerBefreiung` | `Staatsfeiertag` | `Florianitag`
`Muttertag` | `ChristiHimmelfahrt` | `Vatertag`
`Pfingsten` | `PfingstMontag` | `Dreifaltigkeitssonntag`
`Fronleichnam` | `MariäHimmelfahrt` | `Rupertitag`
`TagDerDeutschenEinheit` | `TagDerVolksabstimming` | `Nationalfeiertag`
`Erntedankfest` | `Reformationstag` | `Halloween`
`BeginnWinterzeit` | `Allerheiligen` | `Allerseelen`
`Martinstag` | `Karnevalsbeginn` | `Leopolditag`
`BußUndBettag` | `Thanksgiving` | `Blackfriday`
`Volkstrauertag` | `Nikolaus` | `MariäUnbefleckteEmpfängnis`
`MariaEmpfängnis` | `Totensonntag` | `ErsterAdvent`
`ZweiterAdvent` | `DritterAdvent` | `VierterAdvent`
`Heiligabend` | `Weihnachten` | `Christtag`
`Stefanitag` | `ZweiterWeihnachten` | `Silvester`

`<region>` returns an object of type `region`. It offers a list of public holidays valid in the specified state` | `as well as the name and the shortname of the state as attributes.
`<region>` may be any of:

||||
----|-----|----
`BadenWürttemberg` | `Bayern` | `Berlin`
`Brandenburg` | `Bremen` | `Hamburg`
`Hessen` | `MecklenburgVorpommern` | `Niedersachsen`
`NordrheinWestfalen` | `RheinlandPfalz` | `Saarland`
`Sachsen` | `SachsenAnhalt` | `SchleswigHolstein`
`Thüringen` | `Deutschland` | `All`

The optional region functions second argument `includingSundays` switches the behavior o the region function, so that "gesetzliche Feiertage" on Sundays are included or not. This is important in Brandenburg and refers to Easter and Pentecost sunday. If you are calculating shift costs you will need to know even the holidays "hidden by sundays".

The region functions return the public holidays ("gesetzliche Feiertage"). The function `all` instead returns all the defined "special dates" as well. For example the Penance Day (Buß- und Bettag) or the begin/end of daylight saving time.


`BadenWürttemberg` | `Bayern` | `Berlin`
`Brandenburg` | `Bremen` | `Hamburg`
`Hessen` | `MecklenburgVorpommern` | `Niedersachsen`
`NordrheinWestfalen` | `RheinlandPfalz` | `Saarland`
`Sachsen` | `SachsenAnhalt` | `SchleswigHolstein`
`Thüringen` | `Deutschland` | `Burgenland`
`Kärnten` | `Niederösterreich` | `Oberösterreich`
`Salzburg` | `Steiermark` | `Tirol`
`Vorarlberg` | `Wien` | `Österreich`
`All` | &nbsp; | &nbsp;

The optional region function argument `includingSundays` switches the behavior of the region function to include "gesetzliche Feiertage" that fall on Sundays in its output. This is important in Brandenburg, particularly for Easter and Pentecost Sunday. If you are calculating shift costs you will need to know even the holidays "hidden by Sunday".

The region functions return the public holidays ("gesetzliche Feiertage"). The function `all` returns all defined "special dates", such as Penance Day (Buß- und Bettag) or the begin/end of daylight saving time.

The regional functions for Austrian Bundesländer include saints' days which are state-level holidays, meaning
schools etc. are generally closed but workers don't get the day off by default. If you don't want to
include these days in your planning, it's okay to reference `Österreich` instead as legal holidays are
(more or less) synchronised across Länder.

### Example:

fmt.Println(Ostern(2016))
--> 27.03.2016 Ostern


fmt.Println(BußUndBettag(2016))
--> 16.11.2016 Buß- und Bettag



fmt.Println(Brandenburg(2016))
Expand All @@ -79,7 +90,7 @@ The region functions return the public holidays ("gesetzliche Feiertage"). The f
25.12.2016 Weihnachten
26.12.2016 Zweiter Weihnachtsfeiertag


fmt.Println(Brandenburg(2016, false))
--> Brandenburg (BB)
01.01.2016 Neujahr
Expand All @@ -92,11 +103,11 @@ The region functions return the public holidays ("gesetzliche Feiertage"). The f
31.10.2016 Reformationstag
25.12.2016 Weihnachten
26.12.2016 Zweiter Weihnachtsfeiertag


## Command line tool

A little command line tool is included as well. It can be compiled using `make buildcmd` or `go build cmd/feiertage/feiertage.go` This will create an executable `feiertage`.
A little command line tool is included as well. It can be compiled using `make buildcmd` or `go build cmd/feiertage/feiertage.go` This will create an executable `feiertage`.

See https://github.com/wlbr/feiertage/releases/latest for downloads.

Expand All @@ -105,7 +116,7 @@ See https://github.com/wlbr/feiertage/releases/latest for downloads.
`feiertage: [options] year`<br>
<dl>
<dt>-asTaskjugglerCode (default false)</dt>
<dd>Print the result as valid source code (`leave x y`) for the <a href="http://www.taskjuggler.org/">Taskjuggler</a> planning tool.
<dd>Print the result as valid source code (`leave x y`) for the <a href="http://www.taskjuggler.org/">Taskjuggler</a> planning tool.
<dt>-inklusiveSonntage (default false)</dt>
<dd>Should public holidays on a Sunday be included?</dd>
<dt>-region &lt;regionstring&gt; (default "All")</dt>
Expand All @@ -128,6 +139,16 @@ See https://github.com/wlbr/feiertage/releases/latest for downloads.
&nbsp;SchleswigHolstein<br>
&nbsp;Thüringen<br>
&nbsp;Deutschland<br>
&nbsp;Burgenland<br>
&nbsp;Kärnten<br>
&nbsp;Niederösterreich<br>
&nbsp;Oberösterreich<br>
&nbsp;Salzburg<br>
&nbsp;Steiermark<br>
&nbsp;Tirol<br>
&nbsp;Vorarlberg<br>
&nbsp;Wien<br>
&nbsp;Österreich<br>
&nbsp;All</dd>
</dl>

Expand All @@ -138,4 +159,3 @@ See https://github.com/wlbr/feiertage/releases/latest for downloads.
* Continous Integration: [![Travis Status](https://api.travis-ci.org/wlbr/feiertage.svg?branch=master)](https://travis-ci.org/wlbr/feiertage)
* Test Coverage: [![Coverage Status](https://coveralls.io/repos/github/wlbr/feiertage/badge.svg?branch=master)](https://coveralls.io/github/wlbr/feiertage?branch=master)
* Metrics: [![GoReportCard](https://goreportcard.com/badge/github.com/wlbr/feiertage)](https://goreportcard.com/report/github.com/wlbr/feiertage)

30 changes: 30 additions & 0 deletions cmd/feiertage/feiertage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ func getRegion(region string, year int, includingSundays bool) feiertage.Region
r = feiertage.Thüringen(year, includingSundays)
case "deutschland":
r = feiertage.Deutschland(year, includingSundays)
case "burgenland":
r = feiertage.Burgenland(year, includingSundays)
case "kaernten":
r = feiertage.Kärnten(year, includingSundays)
case "niederoesterreich":
r = feiertage.Niederösterreich(year, includingSundays)
case "oberoesterreich":
r = feiertage.Oberösterreich(year, includingSundays)
case "salzburg":
r = feiertage.Salzburg(year, includingSundays)
case "steiermark":
r = feiertage.Steiermark(year, includingSundays)
case "tirol":
r = feiertage.Tirol(year, includingSundays)
case "vorarlberg":
r = feiertage.Vorarlberg(year, includingSundays)
case "wien":
r = feiertage.Wien(year, includingSundays)
case "oesterreich":
r = feiertage.Österreich(year, includingSundays)
default:
r = feiertage.All(year, includingSundays)
}
Expand All @@ -82,6 +102,16 @@ func main() {
"\t\tSchleswigHolstein\n"+
"\t\tThüringen\n"+
"\t\tDeutschland\n"+
"\t\tBurgenland\n"+
"\t\tKärnten\n"+
"\t\tNiederösterreich\n"+
"\t\tOberösterreich\n"+
"\t\tSalzburg\n"+
"\t\tSteiermark\n"+
"\t\tTirol\n"+
"\t\tVorarlberg\n"+
"\t\tWien\n"+
"\t\tÖsterreich\n"+
"\t\tAll\n")
var includingSundays = flag.Bool("inklusiveSonntage", false, "Sollen Feiertag an Sonntagen mit ausgegeben werden?")
var asTaskjugglerCode = flag.Bool("asTaskjugglerCode", false, "Taskjuggler Code ausgeben.")
Expand Down
4 changes: 1 addition & 3 deletions cmd/feiertage/feiertagecmd_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"testing"
"fmt"
"github.com/wlbr/feiertage"
"regexp"
"testing"
)

func compareAndFail(t *testing.T, f feiertage.Feiertag, d string) {
Expand All @@ -14,7 +14,6 @@ func compareAndFail(t *testing.T, f feiertage.Feiertag, d string) {
}
}


func TestGetRegion(t *testing.T) {
bay := getRegion("Bayern", 2016, true)
fron := bay.Feiertage[7]
Expand All @@ -26,7 +25,6 @@ func TestGetRegion(t *testing.T) {

}


func TestFmtTaskjuggler(t *testing.T) {
reg := getRegion("Brandenburg", 2016, true)
jug := fmtTaskjuggler(reg)
Expand Down
64 changes: 61 additions & 3 deletions feiertage.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Feiertag struct {
Text string
}

//The String function of Firetag will print its concrete Time (Date) plus the name of the Feiertag.
//The String function of Feiertag will print its concrete Time (Date) plus the name of the Feiertag.
func (f Feiertag) String() string {
return fmt.Sprintf("%s %s", f.Format("02.01.2006"), f.Text)
}
Expand Down Expand Up @@ -98,18 +98,23 @@ func Epiphanias(x int) Feiertag {
return Feiertag{time.Date(x, time.January, 6, 0, 0, 0, 0, time.UTC), "Epiphanias"}
}

// HeiligeDreiKönige is another Name for Epiphany, a fixed date.
// HeiligeDreiKönige is another name for Epiphany, a fixed date.
func HeiligeDreiKönige(x int) Feiertag {
e := Epiphanias(x)
e.Text = "Heilige drei Könige"
return e
}

// Valentinstag is Valentine's Daym a fixed date.
// Valentinstag is Valentine's Day, a fixed date.
func Valentinstag(x int) Feiertag {
return Feiertag{time.Date(x, time.February, 14, 0, 0, 0, 0, time.UTC), "Valentinstag"}
}

// Josefitag is St Joseph's Day, a fixed date.
func Josefitag(x int) Feiertag {
return Feiertag{time.Date(x, time.March, 19, 0, 0, 0, 0, time.UTC), "Josefitag"}
}

// Weiberfastnacht is a part of carnival, 52 days before Easter.
func Weiberfastnacht(x int) Feiertag {
o := Ostern(x)
Expand Down Expand Up @@ -200,6 +205,18 @@ func TagDerArbeit(x int) Feiertag {
return Feiertag{time.Date(x, time.May, 1, 0, 0, 0, 0, time.UTC), "Tag der Arbeit"}
}

// Staatsfeiertag is May 1st in Austria, a fixed date.
func Staatsfeiertag(x int) Feiertag {
e := TagDerArbeit(x)
e.Text = "Staatsfeiertag"
return e
}

// Florianitag is St Florian's Day, a fixed date.
func Florianitag(x int) Feiertag {
return Feiertag{time.Date(x, time.May, 4, 0, 0, 0, 0, time.UTC), "Florianitag"}
}

// TagDerBefreiung is Victory in Europe Day, a fixed date.
func TagDerBefreiung(x int) Feiertag {
return Feiertag{time.Date(x, time.May, 8, 0, 0, 0, 0, time.UTC), "Tag der Befreiung"}
Expand Down Expand Up @@ -254,11 +271,21 @@ func MariäHimmelfahrt(x int) Feiertag {
return Feiertag{time.Date(x, time.August, 15, 0, 0, 0, 0, time.UTC), "Mariä Himmelfahrt"}
}

// Rupertitag is St Rupert's Day, a fixed date.
func Rupertitag(x int) Feiertag {
return Feiertag{time.Date(x, time.September, 24, 0, 0, 0, 0, time.UTC), "Rupertitag"}
}

// TagDerDeutschenEinheit is German Unity Day, a fixed date.
func TagDerDeutschenEinheit(x int) Feiertag {
return Feiertag{time.Date(x, time.October, 3, 0, 0, 0, 0, time.UTC), "Tag der deutschen Einheit"}
}

// TagDerVolksabstimming is Referendum Day in Carinthia, a fixed date.
func TagDerVolksabstimming(x int) Feiertag {
return Feiertag{time.Date(x, time.October, 10, 0, 0, 0, 0, time.UTC), "Tag der Volksabstimmung"}
}

// Erntedankfest is Thanksgiving or Harvest Festival, the first Sunday of October.
// The german Erntedankfest is not the same than the US Thanksgiving.
func Erntedankfest(x int) Feiertag {
Expand All @@ -267,6 +294,11 @@ func Erntedankfest(x int) Feiertag {
return Feiertag{o.AddDate(0, 0, d), "Erntedankfest"}
}

// Nationalfeiertag is the Austrian national day, a fixed date.
func Nationalfeiertag(x int) Feiertag {
return Feiertag{time.Date(x, time.October, 26, 0, 0, 0, 0, time.UTC), "Nationalfeiertag"}
}

// Reformationstag is Reformation Day, a fixed date.
func Reformationstag(x int) Feiertag {
return Feiertag{time.Date(x, time.October, 31, 0, 0, 0, 0, time.UTC), "Reformationstag"}
Expand Down Expand Up @@ -304,6 +336,11 @@ func Karnevalsbeginn(x int) Feiertag {
return Feiertag{time.Date(x, time.November, 11, 11, 11, 11, 11, time.UTC), "Karnevalsbeginn"}
}

// Leopolditag is St Leopold's Day, a fixed date.
func Leopolditag(x int) Feiertag {
return Feiertag{time.Date(x, time.November, 15, 0, 0, 0, 0, time.UTC), "Leopolditag"}
}

// BußUndBettag is Penance Day, 11 days before the first Sunday in Advent
func BußUndBettag(x int) Feiertag {
o := time.Date(x, time.November, 22, 0, 0, 0, 0, time.UTC)
Expand Down Expand Up @@ -339,6 +376,13 @@ func MariäUnbefleckteEmpfängnis(x int) Feiertag {
return Feiertag{time.Date(x, time.December, 8, 0, 0, 0, 0, time.UTC), "Mariä unbefleckte Empfängnis"}
}

// MariaEmpfängnis has a shorter name in Austria.
func MariäEmpfängnis(x int) Feiertag {
e := MariäUnbefleckteEmpfängnis(x)
e.Text = "Mariä Empfängnis"
return e
}

// Totensonntag is Sunday in commemoration of the dead, the last Sunday before the fourth Sunday in Advent
func Totensonntag(x int) Feiertag {
o := VierterAdvent(x)
Expand Down Expand Up @@ -380,11 +424,25 @@ func Weihnachten(x int) Feiertag {
return Feiertag{time.Date(x, time.December, 25, 0, 0, 0, 0, time.UTC), "Weihnachten"}
}

// In Austria, Christmas is Christtag.
func Christtag(x int) Feiertag {
e := Weihnachten(x)
e.Text = "Christtag"
return e
}

// ZweiterWeihnachtsfeiertag is day after Christmas, a fixed date
func ZweiterWeihnachtsfeiertag(x int) Feiertag {
return Feiertag{time.Date(x, time.December, 26, 0, 0, 0, 0, time.UTC), "Zweiter Weihnachtsfeiertag"}
}

// In Austria, December 26th is Stefanitag.
func Stefanitag(x int) Feiertag {
e := ZweiterWeihnachtsfeiertag(x)
e.Text = "Stefanitag"
return e
}

// Silvester is NewYearsEve, a fixed date.
func Silvester(x int) Feiertag {
return Feiertag{time.Date(x, time.December, 31, 0, 0, 0, 0, time.UTC), "Silvester"}
Expand Down
Loading