generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'spatie:main' into wessama/add-egypt-holidays
- Loading branch information
Showing
5 changed files
with
144 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,41 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Poland extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'pl'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Nowy Rok' => '01-01', | ||
'Święto Trzech Króli' => '01-06', | ||
'Święto Pracy' => '05-01', | ||
'Święto Konstytucji 3 Maja' => '05-03', | ||
'Święto Wojska Polskiego, Wniebowzięcie Najświętszej Maryi Panny' => '08-15', | ||
'Wszystkich Świętych' => '11-01', | ||
'Święto Niepodległości' => '11-11', | ||
'Boże Narodzenie' => '12-25', | ||
'Drugi Dzień Bożego Narodzenia' => '12-26', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Wielkanoc' => $easter, | ||
'Poniedziałek Wielkanocny' => $easter->addDay(), | ||
'Zielone Świątki' => $easter->addWeeks(7), | ||
'Boże Ciało' => $easter->addDays(60), | ||
]; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Spatie\Holidays\Exceptions\UnsupportedCountry; | ||
|
||
class SriLanka extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'lk'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
// Sri lanka has a committee that decides the holidays for the year | ||
// instead of following a full moon calendar. | ||
|
||
throw UnsupportedCountry::make($this->countryCode()); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/.pest/snapshots/Countries/PolandTest/it_can_calculate_polish_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,54 @@ | ||
[ | ||
{ | ||
"name": "Nowy Rok", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "\u015awi\u0119to Trzech Kr\u00f3li", | ||
"date": "2024-01-06" | ||
}, | ||
{ | ||
"name": "Wielkanoc", | ||
"date": "2024-03-31" | ||
}, | ||
{ | ||
"name": "Poniedzia\u0142ek Wielkanocny", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "\u015awi\u0119to Pracy", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "\u015awi\u0119to Konstytucji 3 Maja", | ||
"date": "2024-05-03" | ||
}, | ||
{ | ||
"name": "Zielone \u015awi\u0105tki", | ||
"date": "2024-05-19" | ||
}, | ||
{ | ||
"name": "Bo\u017ce Cia\u0142o", | ||
"date": "2024-05-30" | ||
}, | ||
{ | ||
"name": "\u015awi\u0119to Wojska Polskiego, Wniebowzi\u0119cie Naj\u015bwi\u0119tszej Maryi Panny", | ||
"date": "2024-08-15" | ||
}, | ||
{ | ||
"name": "Wszystkich \u015awi\u0119tych", | ||
"date": "2024-11-01" | ||
}, | ||
{ | ||
"name": "\u015awi\u0119to Niepodleg\u0142o\u015bci", | ||
"date": "2024-11-11" | ||
}, | ||
{ | ||
"name": "Bo\u017ce Narodzenie", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Drugi Dzie\u0144 Bo\u017cego Narodzenia", | ||
"date": "2024-12-26" | ||
} | ||
] |
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,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate polish holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'pl')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |
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,10 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Spatie\Holidays\Exceptions\UnsupportedCountry; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('cannot calculate sri lanka holidays', function () { | ||
Holidays::for(country: 'lk')->get(); | ||
})->throws(UnsupportedCountry::class); |