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 New Zealand Holidays #207

Merged
merged 2 commits into from
Jun 15, 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
137 changes: 137 additions & 0 deletions src/Countries/NewZealand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use Spatie\Holidays\Concerns\Observable;

class NewZealand extends Country
{
use Observable;

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

protected function allHolidays(int $year): array
{
return array_merge(
$this->observedHolidays($year),
$this->variableHolidays($year),
);
}

protected function observedHolidays(int $year): array

Check failure on line 26 in src/Countries/NewZealand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\NewZealand::observedHolidays() return type has no value type specified in iterable type array.
{
//https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-and-anniversary-dates/
$holidays = [
'New Year\'s Day' => '01-01',
'Day after New Year\'s Day' => '01-02',
'Waitangi Day' => '02-06',
'ANZAC Day' => '04-25',
'Christmas Day' => '12-25',
'Boxing Day' => '12-26',
];

//https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/
foreach ($holidays as $name => $date) {
$observedDay = match ($name) {
'Day after New Year\'s Day' => $this->secondOfJanuary($year),
'Christmas Day' => $this->observedChristmasDay($year),
'Boxing Day' => $this->observedBoxingDay($year),
default => $this->weekendToNextMonday($date, $year),
};

if ($observedDay) {
$holidays[$name.' (Mondayisation)'] = $observedDay;
unset($holidays[$name]);
}
}

return $holidays;
}

protected function variableHolidays(int $year): array

Check failure on line 56 in src/Countries/NewZealand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\NewZealand::variableHolidays() return type has no value type specified in iterable type array.
{
//Easter
$easterSunday = $this->easter($year);
$goodFriday = $easterSunday->subDays(2);
$easterMonday = $easterSunday->addDay();

//Sovereign Birthday
$sovereignTitle = $this->sovereignBirthdayKey($year);
$sovereignMonday = CarbonImmutable::parse("first monday of june {$year}");

//Labour Day
$labourMonday = CarbonImmutable::parse("fourth monday of october {$year}");

return [
'Good Friday' => $goodFriday,
'Easter Monday' => $easterMonday,
$sovereignTitle => $sovereignMonday,
'Matariki' => $this->calculateMatariki($year),
'Labour Day' => $labourMonday,
];
}

protected function secondOfJanuary(int $year): ?CarbonInterface
{
$newYearsDay = (new CarbonImmutable($year.'-01-01'))->startOfDay();
$secondOfJanuary = $newYearsDay->addDay();

return match ($newYearsDay->dayName) {
'Friday' => $secondOfJanuary->next('monday'),
'Saturday', 'Sunday' => $secondOfJanuary->next('tuesday'),
default => null,
};
}

protected function sovereignBirthdayKey(int $year): string
{
return $year >= 2023 ? "King's Birthday" : "Queen's Birthday";
}

private function calculateMatariki(int $year): ?CarbonImmutable
{
//https://www.tepapa.govt.nz/discover-collections/read-watch-play/matariki-maori-new-year/dates-for-matariki-public-holiday
$matarikiDates = [
2022 => '2022-06-24',
2023 => '2023-07-14',
2024 => '2024-06-28',
2025 => '2025-06-20',
2026 => '2026-07-10',
2027 => '2027-06-25',
2028 => '2028-07-14',
2029 => '2029-07-06',
2030 => '2030-06-21',
2031 => '2031-07-11',
2032 => '2032-07-02',
2033 => '2033-06-24',
2034 => '2034-07-07',
2035 => '2035-06-29',
2036 => '2036-07-18',
2037 => '2037-07-10',
2038 => '2038-06-25',
2039 => '2039-07-15',
2040 => '2040-07-06',
2041 => '2041-07-19',
2042 => '2042-07-11',
2043 => '2043-07-03',
2044 => '2044-06-24',
2045 => '2045-07-07',
2046 => '2046-06-29',
2047 => '2047-07-19',
2048 => '2048-07-03',
2049 => '2049-06-25',
2050 => '2050-07-15',
2051 => '2051-06-30',
2052 => '2052-06-21',
];

return isset($matarikiDates[$year])
? CarbonImmutable::createFromFormat('Y-m-d', $matarikiDates[$year])->setTimezone('Pacific/Auckland')
: null; // Return null if year not defined
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "New Year's Day",
"date": "2030-01-01"
},
{
"name": "Day after New Year's Day",
"date": "2030-01-02"
},
{
"name": "Waitangi Day",
"date": "2030-02-06"
},
{
"name": "Good Friday",
"date": "2030-04-19"
},
{
"name": "Easter Monday",
"date": "2030-04-22"
},
{
"name": "ANZAC Day",
"date": "2030-04-25"
},
{
"name": "King's Birthday",
"date": "2030-06-03"
},
{
"name": "Matariki",
"date": "2030-06-21"
},
{
"name": "Labour Day",
"date": "2030-10-28"
},
{
"name": "Christmas Day",
"date": "2030-12-25"
},
{
"name": "Boxing Day",
"date": "2030-12-26"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "Day after New Year's Day",
"date": "2024-01-02"
},
{
"name": "Waitangi Day",
"date": "2024-02-06"
},
{
"name": "Good Friday",
"date": "2024-03-29"
},
{
"name": "Easter Monday",
"date": "2024-04-01"
},
{
"name": "ANZAC Day",
"date": "2024-04-25"
},
{
"name": "King's Birthday",
"date": "2024-06-03"
},
{
"name": "Matariki",
"date": "2024-06-28"
},
{
"name": "Labour Day",
"date": "2024-10-28"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Boxing Day",
"date": "2024-12-26"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "New Year's Day (Mondayisation)",
"date": "2028-01-03"
},
{
"name": "Day after New Year's Day (Mondayisation)",
"date": "2028-01-04"
},
{
"name": "Waitangi Day (Mondayisation)",
"date": "2028-02-07"
},
{
"name": "Good Friday",
"date": "2028-04-14"
},
{
"name": "Easter Monday",
"date": "2028-04-17"
},
{
"name": "ANZAC Day",
"date": "2028-04-25"
},
{
"name": "King's Birthday",
"date": "2028-06-05"
},
{
"name": "Matariki",
"date": "2028-07-14"
},
{
"name": "Labour Day",
"date": "2028-10-23"
},
{
"name": "Christmas Day",
"date": "2028-12-25"
},
{
"name": "Boxing Day",
"date": "2028-12-26"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "New Year's Day",
"date": "2027-01-01"
},
{
"name": "Day after New Year's Day (Mondayisation)",
"date": "2027-01-04"
},
{
"name": "Waitangi Day (Mondayisation)",
"date": "2027-02-08"
},
{
"name": "Good Friday",
"date": "2027-03-26"
},
{
"name": "Easter Monday",
"date": "2027-03-29"
},
{
"name": "ANZAC Day (Mondayisation)",
"date": "2027-04-26"
},
{
"name": "King's Birthday",
"date": "2027-06-07"
},
{
"name": "Matariki",
"date": "2027-06-25"
},
{
"name": "Labour Day",
"date": "2027-10-25"
},
{
"name": "Christmas Day (Mondayisation)",
"date": "2027-12-27"
},
{
"name": "Boxing Day (Mondayisation)",
"date": "2027-12-28"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "New Year's Day (Mondayisation)",
"date": "2022-01-03"
},
{
"name": "Day after New Year's Day (Mondayisation)",
"date": "2022-01-04"
},
{
"name": "Waitangi Day (Mondayisation)",
"date": "2022-02-07"
},
{
"name": "Good Friday",
"date": "2022-04-15"
},
{
"name": "Easter Monday",
"date": "2022-04-18"
},
{
"name": "ANZAC Day",
"date": "2022-04-25"
},
{
"name": "Queen's Birthday",
"date": "2022-06-06"
},
{
"name": "Matariki",
"date": "2022-06-24"
},
{
"name": "Labour Day",
"date": "2022-10-24"
},
{
"name": "Boxing Day",
"date": "2022-12-26"
},
{
"name": "Christmas Day (Mondayisation)",
"date": "2022-12-27"
}
]
Loading
Loading