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 holidays for Tanzania #86

Closed
wants to merge 4 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
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ parameters:
count: 1
path: src/Countries/Netherlands.php

-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Tanzania\\:\\:allHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#"
count: 1
path: src/Countries/Tanzania.php

-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Tanzania\\:\\:variableHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#"
count: 1
path: src/Countries/Tanzania.php

-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#"
count: 1
Expand Down
99 changes: 99 additions & 0 deletions src/Countries/Tanzania.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use IntlCalendar;

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

/** @return array<string, CarbonImmutable> */
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, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Africa/Dar_es_Salaam');

// Eid al-Fitr is on the first day of the 10th month in the calendar
// since the PHP array index begins at 0, it is the 9th month
$eid_al_fitr_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-rgsa');
$eid_al_fitr_cal->set(IntlCalendar::FIELD_MONTH, 9);
$eid_al_fitr_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
$eid_al_fitr_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY);
$eid_al_fitr_cal->clear(IntlCalendar::FIELD_MINUTE);
$eid_al_fitr_cal->clear(IntlCalendar::FIELD_SECOND);
$eid_al_fitr_cal->clear(IntlCalendar::FIELD_MILLISECOND);

// Eid al-Hajj is on the 10th day of the Dhu al-Hijja the 12th month in the calendar
// since the PHP array index begins at 0, it is the 11th month
$eid_al_hajj_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-civil');
$eid_al_hajj_cal->set(IntlCalendar::FIELD_MONTH, 11);
$eid_al_hajj_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10);
$eid_al_hajj_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY);
$eid_al_hajj_cal->clear(IntlCalendar::FIELD_MINUTE);
$eid_al_hajj_cal->clear(IntlCalendar::FIELD_SECOND);
$eid_al_hajj_cal->clear(IntlCalendar::FIELD_MILLISECOND);

// Eid-e-Milad an-Nabi (Mawlid) is on the 12th day of the 3rd month in the calendar
// since the PHP array index begins at 0, it is the 11th month
$mawlid_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-civil');
$mawlid_cal->set(IntlCalendar::FIELD_MONTH, 2);
$mawlid_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 12);
$mawlid_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY);
$mawlid_cal->clear(IntlCalendar::FIELD_MINUTE);
$mawlid_cal->clear(IntlCalendar::FIELD_SECOND);
$mawlid_cal->clear(IntlCalendar::FIELD_MILLISECOND);

$variable_holidays = [
'Easter Monday' => $easter->addDay(),
'Good Friday' => $easter->addDays(-2),
'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()),
'Eid al-Hajj' => CarbonImmutable::createFromTimestamp($eid_al_hajj_cal->toDateTime()->getTimestamp()),
'Maulid Day' => CarbonImmutable::createFromTimestamp($mawlid_cal->toDateTime()->getTimestamp()),
];

// 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
Expand Up @@ -13,19 +13,19 @@
},
{
"name": "Divendres Sant",
"date": "2024-03-29"
"date": "2024-03-28"
},
{
"name": "Dilluns de Pasqua",
"date": "2024-04-01"
"date": "2024-03-31"
},
{
"name": "Festa del Treball",
"date": "2024-05-01"
},
{
"name": "Dilluns de Pentecosta",
"date": "2024-05-20"
"date": "2024-05-19"
},
{
"name": "Assumpci\u00f3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
},
{
"name": "Ostermontag",
"date": "2024-04-01"
"date": "2024-03-31"
},
{
"name": "Staatsfeiertag",
"date": "2024-05-01"
},
{
"name": "Christi Himmelfahrt",
"date": "2024-05-09"
"date": "2024-05-08"
},
{
"name": "Pfingstmontag",
"date": "2024-05-20"
"date": "2024-05-19"
},
{
"name": "Fronleichnam",
"date": "2024-05-30"
"date": "2024-05-29"
},
{
"name": "Mari\u00e4 Himmelfahrt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
},
{
"name": "Paasmaandag",
"date": "2024-04-01"
"date": "2024-03-31"
},
{
"name": "Dag van de Arbeid",
"date": "2024-05-01"
},
{
"name": "OLH Hemelvaart",
"date": "2024-05-09"
"date": "2024-05-08"
},
{
"name": "Pinkstermaandag",
"date": "2024-05-20"
"date": "2024-05-19"
},
{
"name": "Nationale Feestdag",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
},
{
"name": "Sk\u00e6rtorsdag",
"date": "2024-03-28"
"date": "2024-03-27"
},
{
"name": "Langfredag",
"date": "2024-03-29"
"date": "2024-03-28"
},
{
"name": "P\u00e5skedag",
"date": "2024-04-01"
"date": "2024-03-31"
},
{
"name": "Anden P\u00e5skedag",
"date": "2024-04-02"
"date": "2024-04-01"
},
{
"name": "Kristi Himmelfartsdag",
"date": "2024-05-09"
"date": "2024-05-08"
},
{
"name": "Pinse",
"date": "2024-05-19"
"date": "2024-05-18"
},
{
"name": "Anden Pinsedag",
"date": "2024-05-20"
"date": "2024-05-19"
},
{
"name": "Juleaften",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
},
{
"name": "Nagyp\u00e9ntek",
"date": "2024-03-29"
"date": "2024-03-28"
},
{
"name": "H\u00fasv\u00e9th\u00e9tf\u0151",
"date": "2024-04-01"
"date": "2024-03-31"
},
{
"name": "A munka \u00fcnnepe",
"date": "2024-05-01"
},
{
"name": "P\u00fcnk\u00f6sdh\u00e9tf\u0151",
"date": "2024-05-20"
"date": "2024-05-19"
},
{
"name": "\u00c1llamalap\u00edt\u00e1s \u00fcnnepe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
},
{
"name": "Goede Vrijdag",
"date": "2024-03-29"
"date": "2024-03-28"
},
{
"name": "1e Paasdag",
"date": "2024-03-31"
"date": "2024-03-30"
},
{
"name": "2e Paasdag",
"date": "2024-04-01"
"date": "2024-03-31"
},
{
"name": "Koningsdag",
Expand All @@ -25,15 +25,15 @@
},
{
"name": "Hemelvaartsdag",
"date": "2024-05-09"
"date": "2024-05-08"
},
{
"name": "1e Pinksterdag",
"date": "2024-05-19"
"date": "2024-05-18"
},
{
"name": "2e Pinksterdag",
"date": "2024-05-20"
"date": "2024-05-19"
},
{
"name": "1e Kerstdag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
},
{
"name": "Sexta-feira Santa",
"date": "2024-03-29"
"date": "2024-03-28"
},
{
"name": "P\u00e1scoa",
"date": "2024-03-31"
"date": "2024-03-30"
},
{
"name": "Dia da Liberdade",
Expand All @@ -21,7 +21,7 @@
},
{
"name": "Corpo de Deus",
"date": "2024-05-30"
"date": "2024-05-29"
},
{
"name": "Dia de Portugal",
Expand Down
Loading
Loading