Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Uganda Holidays #11

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
],
"require": {
"php": "^8.1",
"nesbot/carbon": "^2.72.1",
"ext-calendar": "*"
"ext-calendar": "*",
"geniusts/hijri-dates": "^1.1",
"nesbot/carbon": "^2.72.1"
},
"require-dev": {
"laravel/prompts": "^0.1.15",
Expand Down
39 changes: 39 additions & 0 deletions src/Countries/Bolivia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Bolivia extends Country
{
public function countryCode(): string
{
return 'bo';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Día de Año Nuevo' => '01-01',
'Día del Estado Plurinacional' => '01-22',
'Día del Trabajador' => '05-01',
'Año Nuevo Aymara' => '06-21',
'Día de la Independencia' => '08-06',
'Día de Todos los Santos' => '11-02',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

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

return [
'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6),
'Martes de Carnaval' => $easter->subWeeks(6)->subDays(5),
'Viernes Santo' => $easter->subDays(2),
'Corpus Christi' => $easter->addWeeks(8)->addDays(4),
];
}
}
30 changes: 30 additions & 0 deletions src/Countries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use GeniusTS\HijriDate\Date;
use GeniusTS\HijriDate\Hijri;
use Spatie\Holidays\Exceptions\InvalidYear;
use Spatie\Holidays\Exceptions\UnsupportedCountry;

Expand Down Expand Up @@ -99,4 +101,32 @@ protected function ensureYearCanBeCalculated(int $year): void
throw InvalidYear::yearTooHigh();
}
}

public static function eidAlFitr(int $year): CarbonImmutable {
// get the Hirji date for the first day of the Gregorian year
$hirji_date = Hijri::convertToHijri(CarbonImmutable::create($year));
// Eid al-Fitr is on the first day of the 10th month in the calendar
if ($hirji_date->month > 10) {
// the date has passed to move to the next year
$hirji_date->year($hirji_date->year + 1);
}
$eid_al_fitr = new Date(1, 10, $hirji_date->year);

return CarbonImmutable::createFromTimestamp( Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month,
$eid_al_fitr->year)->getTimestamp());
}

public static function eidAlAdha(int $year): CarbonImmutable {
// get the Hirji date for the first day of the Gregorian year
$hirji_date = Hijri::convertToHijri(CarbonImmutable::create($year));
// Eid al-Fitr is on the first day of the 10th month in the calendar
if ($hirji_date->month > 10) {
// the date has passed to move to the next year
$hirji_date->year($hirji_date->year + 1);
}
$eid_al_adha = new Date(10, 12, $hirji_date->year);

return CarbonImmutable::createFromTimestamp( Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month,
$eid_al_adha->year)->getTimestamp());
}
}
4 changes: 1 addition & 3 deletions src/Countries/Croatia.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function countryCode(): string
return 'hr';
}

/** @return array<string, CarbonImmutable|string> */
protected function allHolidays(int $year): array
{
return array_merge([
Expand All @@ -32,8 +31,7 @@ protected function allHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/Zagreb');
$easter = $this->easter($year);

return [
'Uskrsni ponedjeljak' => $easter->addDay(),
Expand Down
60 changes: 42 additions & 18 deletions src/Countries/Uganda.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,56 @@ public function countryCode(): string
return 'ug';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
$holidays_by_official_start_date = array();

// Independence day celebrations started in 1962
if ($year >= 1962) {
$holidays_by_official_start_date['Independence Day of Uganda'] = '10-09';
}

// Martyr's day celebrations started in 1964
if ($year >= 1964) {
$holidays_by_official_start_date['Uganda Martyr\'s Day'] = '06-03';
}

// 'NRM Liberation Day celebrations started in 1987
if ($year >= 1987) {
$holidays_by_official_start_date['NRM Liberation Day'] = '01-26';
}

// National Heroes day celebration started in 2001
if ($year >= 2001) {
$holidays_by_official_start_date['National Heroes\' Day'] = '06-09';
}

// Archbishop Janani Luwum Memorial Day celebrations started in 2015
if ($year >= 2015) {
$holidays_by_official_start_date['Archbishop Janani Luwum Memorial Day'] = '02-16';
}
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',
'New Year\'s Day' => '01-01',
'International Women\'s Day' => '03-08',
'Labor Day' => '05-01',
'Christmas Day' => '12-25',
'Boxing Day' => '12-26',
], $this->variableHolidays($year));
'Boxing Day' => '12-26'
], $holidays_by_official_start_date,
$this->variableHolidays($year));
}

/**
* @return array<string, CarbonImmutable>
*/
private function variableHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi');
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Africa/Kampala');

return [
'Good Friday' => $easter->subDays(2),
return array(
'Easter Monday' => $easter->addDay(),
];
'Good Friday' => $easter->addDays(-2),
'Eid al-Fitr' => $this->eidAlFitr($year),
'Eid al-Adha' => $this->eidAlAdha($year)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "D\u00eda de A\u00f1o Nuevo",
"date": "2024-01-01"
},
{
"name": "D\u00eda del Estado Plurinacional",
"date": "2024-01-22"
},
{
"name": "Lunes de Carnaval",
"date": "2024-02-12"
},
{
"name": "Martes de Carnaval",
"date": "2024-02-13"
},
{
"name": "Viernes Santo",
"date": "2024-03-29"
},
{
"name": "D\u00eda del Trabajador",
"date": "2024-05-01"
},
{
"name": "Corpus Christi",
"date": "2024-05-30"
},
{
"name": "A\u00f1o Nuevo Aymara",
"date": "2024-06-21"
},
{
"name": "D\u00eda de la Independencia",
"date": "2024-08-06"
},
{
"name": "D\u00eda de Todos los Santos",
"date": "2024-11-02"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"date": "2024-05-01"
},
{
"name": "Tijelovo",
"name": "Dan dr\u017eavnosti",
"date": "2024-05-30"
},
{
"name": "Dan dr\u017eavnosti",
"name": "Tijelovo",
"date": "2024-05-30"
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "NRM Liberation Day",
"date": "2024-01-26"
},
{
"name": "Archbishop Janani Luwum Memorial 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": "Eid al-Fitr",
"date": "2024-04-09"
},
{
"name": "Labor Day",
"date": "2024-05-01"
},
{
"name": "Uganda Martyr's Day",
"date": "2024-06-03"
},
{
"name": "National Heroes' Day",
"date": "2024-06-09"
},
{
"name": "Eid al-Adha",
"date": "2024-06-17"
},
{
"name": "Independence Day of Uganda",
"date": "2024-10-09"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Boxing Day",
"date": "2024-12-26"
}
]
13 changes: 0 additions & 13 deletions tests/Countries/AustriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Countries\Austria;
use Spatie\Holidays\Holidays;

it('can calculate austrian holidays', function () {
Expand All @@ -17,15 +16,3 @@

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

it('can calculate austrian holidays with region holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(Austria::make('bg'))->get();

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

expect(formatDates($holidays))->toMatchSnapshot();
})->skip('Austria class has to be extended with regions first.');
18 changes: 18 additions & 0 deletions tests/Countries/BoliviaTest.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 bolivian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'bo')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty()
->and(formatDates($holidays))->toMatchSnapshot();

});
23 changes: 23 additions & 0 deletions tests/Countries/CountryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Spatie\Holidays\Countries\Country;

it('can compute Eid al-Fitr date correctly', function (int $year, string $date) {
expect(Country::eidAlFitr($year)->format('Y-m-d'))->toBe($date);
})->with([
[2024, '2024-04-09'],
[2020, '2020-05-24'],
[2009, '2009-09-21'],
[1995, '1995-03-02']
]);


it('can compute Eid al-Adha date correctly', function (int $year, string $date) {
expect(Country::eidAlAdha($year)->format('Y-m-d'))->toBe($date);
})->with([
[2024, '2024-06-16'],
[2023, '2023-06-28'],
[2019, '2019-08-11'],
[2007, '2007-12-20'],
[1994, '1994-05-20']
]);
3 changes: 2 additions & 1 deletion tests/Countries/UgandaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate ugandan holidays', function () {
it('can calculate uganda holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'ug')->get();
Expand All @@ -15,4 +15,5 @@
->not()->toBeEmpty();

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

});