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

Add Tanzania national holiday #98

Merged
merged 4 commits into from
Jan 27, 2024
Merged
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
64 changes: 64 additions & 0 deletions src/Countries/Tanzania.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use IntlCalendar;

class Tanzania extends Country
{
public function countryCode(): string
{
return 'tz';
}

protected function allHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
'Labor Day' => '05-01',
'Saba Saba Day' => '07-07',
'Farmers Day (Nane Nane Day)' => '08-08',
'Christmas Day' => '12-25',
'Boxing Day' => '12-26'
], $this->variableHolidays($year));
}

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

$variable_holidays = [
'Easter Monday' => $easter->addDay(),
'Good Friday' => $easter->addDays(-2),
];

// Zanzibar Revolutionary Day celebrations started in 1964
if ($year >= 1964) {
$variable_holidays['Zanzibar Revolutionary Day'] = '01-12';
}

// Karume Day celebrations started in 1973
if ($year >= 1973) {
$variable_holidays['Karume Day'] = '04-07';
}

// 'Union Day celebrations started in 1964
if ($year >= 1964) {
$variable_holidays['Union Day'] = '04-26';
}

// Nyerere Day day celebrations started in 2000
if ($year >= 2000) {
$variable_holidays['Nyerere Day'] = '10-14';
}

// Independence Day celebrations started in 1961
if ($year >= 1961) {
$variable_holidays['Independence Day'] = '12-09';
}

return $variable_holidays;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "Zanzibar Revolutionary Day",
"date": "2024-01-12"
},
{
"name": "Good Friday",
"date": "2024-03-29"
},
{
"name": "Easter Monday",
"date": "2024-04-01"
},
{
"name": "Karume Day",
"date": "2024-04-07"
},
{
"name": "Union Day",
"date": "2024-04-26"
},
{
"name": "Labor Day",
"date": "2024-05-01"
},
{
"name": "Saba Saba Day",
"date": "2024-07-07"
},
{
"name": "Farmers Day (Nane Nane Day)",
"date": "2024-08-08"
},
{
"name": "Nyerere Day",
"date": "2024-10-14"
},
{
"name": "Independence Day",
"date": "2024-12-09"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Boxing Day",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/TanzaniaTest.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 tanzania holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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