From 20f63a357115736339cbce3ddfae82678bd79a54 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 24 Jun 2015 17:36:19 +0200 Subject: [PATCH] add holidays for germany (basic version) path is set to top level add beta version of german holidays add more information to the docstring add examplke to readme file add eaxample to readme file correct readme add list of states add import to example add section header try different layout another test add note add revert --- README.rst | 35 ++++++++++++++++++- holiday/countries/germany.py | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 holiday/countries/germany.py diff --git a/README.rst b/README.rst index 678720b..80d5e11 100644 --- a/README.rst +++ b/README.rst @@ -28,11 +28,12 @@ This version only contains (incomplete) holiday information from: * Brazil * Poland * United Kingdom - +* Germany Getting started =============== +To get the latest version you have to clone this repository. Installation ------------ @@ -43,6 +44,8 @@ Installation Usage ----- +**Brazil** + Suppose you want to get the holidays for 2014 in the city of São Paulo, state of São Paulo, Brazil. You would do this:: @@ -70,6 +73,36 @@ state of São Paulo, Brazil. You would do this:: datetime.date(2014, 11, 20): 'Dia da Consciência Negra', datetime.date(2014, 12, 25): 'Natal'} +**Germany** + +To get the holidays of Germany you should use the abbreviations for the german federal states like 'Germany/BY ' for Bayern. + +:BW: Baden-Württemberg +:BY: Bayern +:BE: Berlin +:BB: Brandenburg +:HB: Bremen +:HH: Hamburg +:HE: Hessen +:MV: Mecklenburg-Vorpommern +:NI: Niedersachsen +:NW: Nordrhein-Westfalen +:RP: Rheinland-Pfalz +:SL: Saarland +:SN: Sachsen +:ST: Sachsen-Anhalt +:SH: Schleswig-Holstein +:TH: Thüringen + +Example:: + + from holiday import get_holidays + adict = holiday.get_holidays(year=2015, place='Germany/BY') + print(adict) + +Note +------ + We don't currently help calculations involving business days; maybe we should. But many approaches are possible. See, for instance, http://pandas.pydata.org/pandas-docs/stable/timeseries.html#custom-business-days-experimental diff --git a/holiday/countries/germany.py b/holiday/countries/germany.py new file mode 100644 index 0000000..10df6dc --- /dev/null +++ b/holiday/countries/germany.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +'''Holiday information for Brazil.''' + +from __future__ import (absolute_import, division, print_function, + unicode_literals) +from datetime import date, timedelta +from dateutil import easter + + +def get_holidays(year, place=['Germany', None, None], scope='legal', _=str): + """ Returns German holiday dates. Use the abbreviations for the german + federal states like 'Germany/BY ' for Bayern. + BW: Baden-Württemberg + BY: Bayern + BE: Berlin + BB: Brandenburg + HB: Bremen + HH: Hamburg + HE: Hessen + MV: Mecklenburg-Vorpommern + NI: Niedersachsen + NW: Nordrhein-Westfalen + RP: Rheinland-Pfalz + SL: Saarland + SN: Sachsen + ST: Sachsen-Anhalt + SH: Schleswig-Holstein + TH: Thüringen + Example: get_holidays(year=2015, place='Germany/BY') + """ + + eastr = easter.easter(year) + + adict = { + date(year, 1, 1): 'Neujahr', + date(year, 5, 1): 'Tag der Arbeit', + date(year, 10, 3): 'Tag der Deutschen Einheit', + date(year, 12, 25): '1. Weihnachtstag', + date(year, 12, 26): '2. Weihnachtstag', + eastr - timedelta(days=2): 'Karfreitag', + eastr: 'Ostersonntag', + eastr + timedelta(days=1): 'Ostermontag', + eastr + timedelta(days=39): 'Christi Himmelfahrt', + eastr + timedelta(days=50): 'Pfingstmontag', + } # These are the *national* holidays. + + if place[1].upper() in ('BW', 'BY', 'ST'): + adict[date(year, 1, 6)] = 'Heilige Drei Könige' + + if place[1] in ('BW', 'BY', 'HE', 'NW', 'RP', 'SL'): + adict[eastr + timedelta(days=60)] = 'Frohnleichnam' + + if place[1].upper() in ('BY', 'SL'): + adict[date(year, 8, 15)] = 'Mariä Himmelfahrt' + + if place[1].upper() in ('BB', 'MV', 'SN', 'ST', 'TH'): + adict[date(year, 10, 31)] = 'Reformationstag' + + if place[1].upper() in ('BW', 'BY', ): + adict[date(year, 11, 1)] = 'Allerheiligen' + + return adict + + +if __name__ == "__main__": + from pprint import pprint + pprint(get_holidays(2015, place=['Germany', 'BE', 'Berlin']))