Skip to content

Commit

Permalink
Merge pull request #126 from Crawford30/feat/add_uganda_holidays
Browse files Browse the repository at this point in the history
Added Uganda Public Holidays and  Unit Tests
  • Loading branch information
freekmurze authored Jan 19, 2024
2 parents 175ce21 + 770958c commit 67f2148
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/Countries/Uganda.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Date 19-Jan-2024
*
* @author Joel Crawford Email: <[email protected]> Github: <https://github.com/Crawford30> LinkedIn: <https://www.linkedin.com/in/Crawford30>
*/

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Uganda extends Country
{

public function countryCode(): string
{
return 'ug';
}

/**
* @inheritDoc
*/
protected function allHolidays(int $year): array
{

/**
* 'New Year' => '01-01', Format:: Month-Date
*/
return array_merge([
"New Year's Day" => "01-01",
"NRM Liberation Day" => "01-26",
"Archbishop Janani Luwum Day" => "02-16",
"International Women's Day" => "03-08",
"Labour Day" => "05-01",
"Martyrs' Day" => "06-03",
"National Hereos Day" => "06-09",
"Independence Day" => "10-09",
"Christmas Day" => "12-25",
"Boxing Day" => "12-26",
], $this->variableHolidays($year));
}

/**
* @param int $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(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "NRM Liberation Day",
"date": "2024-01-26"
},
{
"name": "Archbishop Janani Luwum Day",
"date": "2024-02-16"
},
{
"name": "International Women's Day",
"date": "2024-03-08"
},
{
"name": "Good Friday",
"date": "2024-03-29"
},
{
"name": "Easter Monday",
"date": "2024-04-01"
},
{
"name": "Labour Day",
"date": "2024-05-01"
},
{
"name": "Martyrs' Day",
"date": "2024-06-03"
},
{
"name": "National Hereos Day",
"date": "2024-06-09"
},
{
"name": "Independence Day",
"date": "2024-10-09"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Boxing Day",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/UgandaTest.php
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: 'ug')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});

0 comments on commit 67f2148

Please sign in to comment.