generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
19 changed files
with
1,047 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/.pest/snapshots/Countries/GermanyTest/it_can_calculate_german_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
50 changes: 50 additions & 0 deletions
50
...t/it_can_get_german_holidays_for_other_regions_with_data_set____BB___12_____BB___12_.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
42 changes: 42 additions & 0 deletions
42
...t/it_can_get_german_holidays_for_other_regions_with_data_set____BE___10_____BE___10_.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
50 changes: 50 additions & 0 deletions
50
...t/it_can_get_german_holidays_for_other_regions_with_data_set____BW___12_____BW___12_.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
Oops, something went wrong.