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.
- Loading branch information
1 parent
2a0d024
commit 5941d7b
Showing
3 changed files
with
105 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 Malawi extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'mw'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'New Years Day' => '01-01', | ||
'John Chilembwe Day' => '01-15', | ||
'Martyrs Day' => '03-03', | ||
'Labour Day' => '05-01', | ||
'Kamuzu Day' => '05-14', | ||
'Independence Day' => '07-06', | ||
'Mothers Day' => '10-15', | ||
'Christmas Day' => '12-25', | ||
'Boxing Day' => '12-26', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** | ||
* @return array<string, CarbonImmutable> | ||
*/ | ||
private function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); | ||
|
||
return [ | ||
'Good Friday' => $easter->subDays(2), | ||
'Easter Monday' => $easter->addDay(), | ||
]; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_ugandan_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,46 @@ | ||
[ | ||
{ | ||
"name": "New Years Day", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "John Chilembwe Day", | ||
"date": "2024-01-15" | ||
}, | ||
{ | ||
"name": "Martyrs Day", | ||
"date": "2024-03-03" | ||
}, | ||
{ | ||
"name": "Good Friday", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Easter Monday", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Labour Day", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Kamuzu Day", | ||
"date": "2024-05-14" | ||
}, | ||
{ | ||
"name": "Independence Day", | ||
"date": "2024-07-06" | ||
}, | ||
{ | ||
"name": "Mothers Day", | ||
"date": "2024-10-15" | ||
}, | ||
{ | ||
"name": "Christmas Day", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Boxing Day", | ||
"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 ugandan holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'mw')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |