Skip to content

Commit

Permalink
Adding German holidays (#8)
Browse files Browse the repository at this point in the history
* Create Germany.php

* Create GermanyTest.php

* Test Snapshot

* Change easter to class method

* Adding regional state holidays

* Adding state testing snapshots

* Pint fixes

* Moving failing test to fixed TestTime

* phpstan fixing return

* Test fix: Count regional holidays by numbers from wikipedia & Fixing Bug for regional SN,BB, HE
  • Loading branch information
arnebr authored Jan 25, 2024
1 parent 0acd603 commit ab04ec4
Show file tree
Hide file tree
Showing 19 changed files with 1,047 additions and 0 deletions.
189 changes: 189 additions & 0 deletions src/Countries/Germany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

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, 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->historicalHolidays($year), $this->regionHolidays($year));
}

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

$easter = $this->easter($year);

return [
'Karfreitag' => $easter->subDays(2),
'Ostermontag' => $easter->addDay(),
'Himmelfahrt' => $easter->addDays(39),
'Pfingstmontag' => $easter->addDays(50),
];
}

/** @return array<string, CarbonImmutable|string> */
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 [
'Ostersonntag' => $easter,
'Reformationstag' => '10-31',
'Pfingstsonntag' => $easter->addDays(49),
];
} else {
return [
'Ostersonntag' => $easter,
'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,
'Pfingstsonntag' => $easter->addDays(49),
'Fronleichnam' => $easter->addDays(60),
];
case 'DE-MV':
$mvHolidays = [];
if ($year >= 1990) {
$mvHolidays['Reformationstag'] = '10-31';
}
if ($year >= 2023) {
$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) {
$snHolidays['Reformationstag'] = '10-31';

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

}

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

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

return $thHolidays;

}

return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"name": "Neujahr",
"date": "2024-01-01"
},
{
"name": "Karfreitag",
"date": "2024-03-29"
},
{
"name": "Ostermontag",
"date": "2024-04-01"
},
{
"name": "Tag der Arbeit",
"date": "2024-05-01"
},
{
"name": "Himmelfahrt",
"date": "2024-05-09"
},
{
"name": "Pfingstmontag",
"date": "2024-05-20"
},
{
"name": "Tag der deutschen Einheit",
"date": "2024-10-03"
},
{
"name": "1. Weihnachtstag",
"date": "2024-12-25"
},
{
"name": "2. Weihnachtstag",
"date": "2024-12-26"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "Neujahr",
"date": "2024-01-01"
},
{
"name": "Karfreitag",
"date": "2024-03-29"
},
{
"name": "Ostersonntag",
"date": "2024-03-31"
},
{
"name": "Ostermontag",
"date": "2024-04-01"
},
{
"name": "Tag der Arbeit",
"date": "2024-05-01"
},
{
"name": "Himmelfahrt",
"date": "2024-05-09"
},
{
"name": "Pfingstsonntag",
"date": "2024-05-19"
},
{
"name": "Pfingstmontag",
"date": "2024-05-20"
},
{
"name": "Tag der deutschen Einheit",
"date": "2024-10-03"
},
{
"name": "Reformationstag",
"date": "2024-10-31"
},
{
"name": "1. Weihnachtstag",
"date": "2024-12-25"
},
{
"name": "2. Weihnachtstag",
"date": "2024-12-26"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "Neujahr",
"date": "2024-01-01"
},
{
"name": "Internationaler Frauentag",
"date": "2024-03-08"
},
{
"name": "Karfreitag",
"date": "2024-03-29"
},
{
"name": "Ostermontag",
"date": "2024-04-01"
},
{
"name": "Tag der Arbeit",
"date": "2024-05-01"
},
{
"name": "Himmelfahrt",
"date": "2024-05-09"
},
{
"name": "Pfingstmontag",
"date": "2024-05-20"
},
{
"name": "Tag der deutschen Einheit",
"date": "2024-10-03"
},
{
"name": "1. Weihnachtstag",
"date": "2024-12-25"
},
{
"name": "2. Weihnachtstag",
"date": "2024-12-26"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "Neujahr",
"date": "2024-01-01"
},
{
"name": "Heilige Drei K\u00f6nige",
"date": "2024-01-06"
},
{
"name": "Karfreitag",
"date": "2024-03-29"
},
{
"name": "Ostermontag",
"date": "2024-04-01"
},
{
"name": "Tag der Arbeit",
"date": "2024-05-01"
},
{
"name": "Himmelfahrt",
"date": "2024-05-09"
},
{
"name": "Pfingstmontag",
"date": "2024-05-20"
},
{
"name": "Fronleichnam",
"date": "2024-05-30"
},
{
"name": "Tag der deutschen Einheit",
"date": "2024-10-03"
},
{
"name": "Allerheiligen",
"date": "2024-11-01"
},
{
"name": "1. Weihnachtstag",
"date": "2024-12-25"
},
{
"name": "2. Weihnachtstag",
"date": "2024-12-26"
}
]
Loading

0 comments on commit ab04ec4

Please sign in to comment.