/
GermanyProvider.cs
173 lines (149 loc) · 7.19 KB
/
GermanyProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using Nager.Date.Contract;
using Nager.Date.Model;
using System.Collections.Generic;
using System.Linq;
using System;
namespace Nager.Date.PublicHolidays
{
/// <summary>
/// Germany
/// </summary>
public class GermanyProvider : IPublicHolidayProvider, ICountyProvider
{
private readonly ICatholicProvider _catholicProvider;
/// <summary>
/// GermanyProvider
/// </summary>
/// <param name="catholicProvider"></param>
public GermanyProvider(ICatholicProvider catholicProvider)
{
this._catholicProvider = catholicProvider;
}
/// <summary>
/// GetCounties
/// </summary>
/// <returns></returns>
public IDictionary<string, string> GetCounties()
{
return new Dictionary<string, string>
{
{ "DE-BW", "Baden-Württemberg" },
{ "DE-BY", "Bayern" },
{ "DE-BE", "Berlin" },
{ "DE-BB", "Brandenburg" },
{ "DE-HB", "Bremen" },
{ "DE-HH", "Hamburg" },
{ "DE-HE", "Hessen" },
{ "DE-MV", "Mecklenburg-Vorpommern" },
{ "DE-NI", "Niedersachsen" },
{ "DE-NW", "Nordrhein-Westfalen" },
{ "DE-RP", "Rheinland-Pfalz" },
{ "DE-SL", "Saarland" },
{ "DE-SN", "Sachsen" },
{ "DE-ST", "Sachsen-Anhalt" },
{ "DE-SH", "Schleswig-Holstein" },
{ "DE-TH", "Thüringen" }
};
}
/// <summary>
/// Get
/// </summary>
/// <param name="year">The year</param>
/// <returns></returns>
public IEnumerable<PublicHoliday> Get(int year)
{
var countryCode = CountryCode.DE;
var easterSunday = this._catholicProvider.EasterSunday(year);
var items = new List<PublicHoliday>();
items.Add(new PublicHoliday(year, 1, 1, "Neujahr", "New Year's Day", countryCode, 1967));
items.Add(new PublicHoliday(year, 1, 6, "Heilige Drei Könige", "Epiphany", countryCode, 1967, new string[] { "DE-BW", "DE-BY", "DE-ST" }));
items.Add(new PublicHoliday(year, 3, 8, "Internationaler Frauentag", "International Women's Day", countryCode, 2019, new string[] { "DE-BE" }));
items.Add(new PublicHoliday(easterSunday.AddDays(-2), "Karfreitag", "Good Friday", countryCode));
items.Add(new PublicHoliday(easterSunday.AddDays(1), "Ostermontag", "Easter Monday", countryCode, 1642));
items.Add(new PublicHoliday(year, 5, 1, "Tag der Arbeit", "Labour Day", countryCode));
items.Add(new PublicHoliday(easterSunday.AddDays(39), "Christi Himmelfahrt", "Ascension Day", countryCode));
items.Add(new PublicHoliday(easterSunday.AddDays(50), "Pfingstmontag", "Whit Monday", countryCode));
items.Add(new PublicHoliday(easterSunday.AddDays(60), "Fronleichnam", "Corpus Christi", countryCode,null, new string[] { "DE-BW", "DE-BY", "DE-HE", "DE-NW", "DE-RP", "DE-SL" }));
items.Add(new PublicHoliday(year, 8, 15, "Mariä Himmelfahrt", "Assumption Day", countryCode, null, new string[] { "DE-SL" }));
items.Add(new PublicHoliday(year, 9, 20, "Weltkindertag", "World Children's Day", countryCode, 2019, new string[] { "DE-TH" }));
items.Add(new PublicHoliday(year, 10, 3, "Tag der Deutschen Einheit", "German Unity Day", countryCode));
items.Add(new PublicHoliday(year, 11, 1, "Allerheiligen", "All Saints' Day", countryCode, null, new string[] { "DE-BW", "DE-BY", "DE-NW", "DE-RP", "DE-SL" }));
items.Add(new PublicHoliday(year, 12, 25, "Erster Weihnachtstag", "Christmas Day", countryCode));
items.Add(new PublicHoliday(year, 12, 26, "Zweiter Weihnachtstag", "St. Stephen's Day", countryCode));
var prayerDay = this.GetPrayerDay(year, countryCode);
if (prayerDay != null)
{
items.Add(prayerDay);
}
var liberationDay = this.GetLiberationDay(year, countryCode);
if (liberationDay != null)
{
items.Add(liberationDay);
}
items.Add(this.GetReformationDay(year, CountryCode.DE));
return items.OrderBy(o => o.Date);
}
private PublicHoliday GetReformationDay(int year, CountryCode countryCode)
{
var localName = "Reformationstag";
var englishName = "Reformation Day";
if (year == 2017)
{
//In commemoration of the 500th anniversary of the beginning of the Reformation, it was unique as a whole German holiday
return new PublicHoliday(year, 10, 31, localName, englishName, countryCode, null);
}
var counties = new List<string> { "DE-BB", "DE-MV", "DE-SN", "DE-ST", "DE-TH" };
if (year >= 2018)
{
counties.AddRange(new[] { "DE-HB", "DE-HH", "DE-NI", "DE-SH" });
}
return new PublicHoliday(year, 10, 31, localName, englishName, countryCode, null, counties.ToArray());
}
private PublicHoliday GetPrayerDay(int year, CountryCode countryCode)
{
var dayOfPrayer = this._catholicProvider.AdventSunday(year).AddDays(-11);
var localName = "Buß- und Bettag";
var englishName = "Repentance and Prayer Day";
if (year >= 1934 && year < 1939)
{
return new PublicHoliday(dayOfPrayer, localName, englishName, countryCode);
}
else if (year >= 1945 && year <= 1980)
{
return new PublicHoliday(dayOfPrayer, localName, englishName, countryCode, null, new string[] { "DE-BW", "DE-BE", "DE-HB", "DE-HH", "DE-HE", "DE-NI", "DE-NW", "DE-RP", "DE-SL", "DE-SH" });
}
else if (year >= 1981 && year <= 1989)
{
return new PublicHoliday(dayOfPrayer, localName, englishName, countryCode, null, new string[] { "DE-BW", "DE-BY", "DE-BE", "DE-HB", "DE-HH", "DE-HE", "DE-NI", "DE-NW", "DE-RP", "DE-SL", "DE-SH" });
}
else if (year >= 1990 && year <= 1994)
{
return new PublicHoliday(dayOfPrayer, localName, englishName, countryCode);
}
else if (year >= 1995)
{
return new PublicHoliday(dayOfPrayer, localName, englishName, countryCode, null, new string[] { "DE-SN" });
}
return null;
}
private PublicHoliday GetLiberationDay(int year, CountryCode countryCode)
{
if (year == 2020)
{
return new PublicHoliday(new DateTime(2020, 5, 8), "Tag der Befreiung", "Liberation Day", countryCode, null, new string[] { "DE-BE" });
}
return null;
}
/// <summary>
/// Get the Holiday Sources
/// </summary>
/// <returns></returns>
public IEnumerable<string> GetSources()
{
return new string[]
{
"https://de.wikipedia.org/wiki/Gesetzliche_Feiertage_in_Deutschland",
};
}
}
}