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

Adding German holidays #8

Merged
merged 13 commits into from
Jan 25, 2024
Prev Previous commit
Next Next commit
Adding regional state holidays
  • Loading branch information
arnebr committed Jan 21, 2024
commit a1844ab6f55e96dceeadc1f7215a0a4285da0a58
175 changes: 173 additions & 2 deletions src/Countries/Germany.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,42 @@

class Germany extends Country
{
protected function __construct(
protected ?string $region = null,
) {
}
public function countryCode(): string
{
return 'de';
}
private function getRepentanceAndPrayerDay(int $year):string{
$repentanceAndPrayerDay= new CarbonImmutable('next wednesday '.$year.'-11-15', 'Europe/Berlin');
return $repentanceAndPrayerDay->format('m-d');
}
/** @return array<string, string> */
protected function historicalHolidays(int $year): array
{
$historicalHolidays= [];
if($year >=1990 && $year <=1994) {
$historicalHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year);
}
if($year === 2017) {
$historicalHolidays['Reformationstag'] = '10-31';
}
return $historicalHolidays;
}

/** @return array<string, string|CarbonImmutable> */
/** @return array<string, CarbonImmutable|string> */
protected function allHolidays(int $year): array
{

return array_merge([
'Neujahr' => '01-01',
'Tag der deutschen Einheit' => '10-03',
'Tag der Arbeit'=> '05-01',
'1. Weihnachtstag' => '12-25',
'2. Weihnachtstag' => '12-26'
], $this->variableHolidays($year));
], $this->variableHolidays($year), $this->historicalHolidays($year), $this->regionHolidays($year));
}

/** @return array<string, CarbonImmutable> */
Expand All @@ -36,4 +57,154 @@ protected function variableHolidays(int $year): array
'Pfingstmontag' => $easter->addDays(50),
];
}
/** @return array<string, CarbonImmutable> */
protected function regionHolidays(int $year): array
{
$easter = $this->easter($year);
switch ($this->region) {
case 'DE-BW':
return [
'Heilige Drei Könige' => '01-06',
'Fronleichnam' => $easter->addDays(60),
'Allerheiligen' => '11-01',
];
case 'DE-BY':
return [
'Heilige Drei Könige' => '01-06',
'Fronleichnam' => $easter->addDays(60),
'Allerheiligen' => '11-01',
'Mariä Himmelfahrt' => '08-15',
];

case 'DE-BE':
if($year >=2019)
{
return [
'Internationaler Frauentag' => '03-08',
];
}
else
{
return [

];
}
case 'DE-BB':
if($year >=1991)
{
return [
'Reformationstag' => '10-31',
'Pfingstsonntag' => $easter->addDays(49),
];
}
else
{
return [
'Pfingstsonntag' => $easter->addDays(49),
];
}
case 'DE-HB':
case 'DE-HH':
case 'DE-NI':
case 'DE-SH':
if($year >=2017)
{
return [
'Reformationstag' => '10-31',
];
}
else
{
return [

];
}

case 'DE-HE':
return [
'Ostersonntag' => $easter,
'Fronleichnam' => $easter->addDays(60),
];
case 'DE-MV':
$mvHolidays = [];
if($year >=1990)
{
array_push($mvHolidays, [
'Reformationstag' => '10-31',
]);

}
if($year >=2023)
{
array_push($mvHolidays, [
'Internationaler Frauentag'=> '03-08',
]);

}
return $mvHolidays;
case 'DE-NW':
case 'DE-RP':

return [
'Fronleichnam' => $easter->addDays(60),
'Allerheiligen' => '11-01',
];
case 'DE-SL':
return [
'Fronleichnam' => $easter->addDays(60),
'Allerheiligen' => '11-01',
'Mariä Himmelfahrt' => '08-15',
];
case 'DE-SN':
$snHolidays = [];
if($year >=1990)
{
array_push($snHolidays, [
'Reformationstag' => '10-31',
]);

}
if($year >1994)
{
array_push($snHolidays, [
'Buß- und Bettag' => $this->getRepentanceAndPrayerDay($year)
]);

}
return $snHolidays;
case 'DE-ST':
$stHolidays = [];
if($year >=1990)
{
array_push($stHolidays, [
'Reformationstag' => '10-31',
]);

}
if($year >=1991){
array_push($stHolidays, [
'Heilige Drei Könige' => '01-06',
]);
}
case 'DE-TH':
$thHolidays = [];
if($year >=1990)
{
array_push($thHolidays, [
'Reformationstag' => '10-31',
]);

}
if($year >=2019){
array_push($thHolidays, [
'Weltkindertag' => '09-20',
]);
}
return $thHolidays;

}


return [];
}
}
28 changes: 28 additions & 0 deletions tests/Countries/GermanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,31 @@
expect(formatDates($holidays))->toMatchSnapshot();

});


it('can calculate german historical reformationstag in year 2017', function () {
CarbonImmutable::setTestNowAndTimezone('2017-01-01');

$holiday=Holidays::for('de')->isHoliday('2017-10-31');

expect($holiday)->toBeTrue();

});
it('can calculate german historical reformationstag in year 2018 is not a holiday', function () {
CarbonImmutable::setTestNowAndTimezone('2018-01-01');

$holiday=Holidays::for('de')->isHoliday('2018-10-31');

expect($holiday)->toBeFalse();

});

it('can calculate german buß- und bettag in year 1990', function () {
CarbonImmutable::setTestNowAndTimezone('1990-01-01');

$holiday=Holidays::for('de')->isHoliday('1990-10-03');

expect($holiday)->toBeTrue();

});