Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions src/Concerns/Observable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ protected function weekendToNextMonday(string|CarbonInterface $date, int $year):
return null;
}

protected function dayToNextFridayOrMonday(string|CarbonInterface $date, int $year): ?CarbonInterface
{
$christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay();
$boxingDay = (new CarbonImmutable($year.'-12-26'))->startOfDay();
$newYearDay = (new CarbonImmutable($year.'-01-01'))->startOfDay();

if (is_string($date)) {
$date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay();
}

if ($date->isSameDay($christmasDay) || $date->isSameDay($boxingDay) || $date->isSameDay($newYearDay)) {
return $date;
}

if ($date->isWeekend()) {
return $date->next('monday');
}

if ($date->isWeekday() && !$date->isFriday()) {
return $date->next('friday');
}

return null;
}

protected function sundayToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface
{
if (is_string($date)) {
Expand Down
5 changes: 2 additions & 3 deletions src/Countries/Ghana.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ protected function observedHolidays(int $year): array
'Constitution Day' => '01-07',
'Independence Day' => '03-06',
'May Day' => '05-01',
"Founder's Day" => '08-04',
'Kwame Nkrumah Memorial Day' => '09-21',
"Founder's Day" => '09-21',
'Christmas Day' => '12-25',
'Boxing Day' => '12-26',
];
Expand All @@ -41,7 +40,7 @@ protected function observedHolidays(int $year): array
$observedDay = match ($name) {
'Christmas Day' => $this->observedChristmasDay($year),
'Boxing Day' => $this->observedBoxingDay($year),
default => $this->weekendToNextMonday($date, $year),
default => $this->dayToNextFridayOrMonday($date, $year),
};

if ($observedDay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"name": "Independence Day",
"date": "2024-03-06"
"date": "2024-03-08"
},
{
"name": "Good Friday",
Expand All @@ -21,14 +21,10 @@
},
{
"name": "May Day",
"date": "2024-05-01"
"date": "2024-05-03"
},
{
"name": "Founder's Day",
"date": "2024-08-05"
},
{
"name": "Kwame Nkrumah Memorial Day",
"date": "2024-09-23"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"name": "Independence Day",
"date": "2024-03-06"
"date": "2024-03-08"
},
{
"name": "Good Friday",
Expand All @@ -21,14 +21,10 @@
},
{
"name": "May Day",
"date": "2024-05-01"
"date": "2024-05-03"
},
{
"name": "Founder's Day",
"date": "2024-08-05"
},
{
"name": "Kwame Nkrumah Memorial Day",
"date": "2024-09-23"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"name": "Independence Day",
"date": "2024-03-06"
"date": "2024-03-08"
},
{
"name": "Good Friday",
Expand All @@ -21,14 +21,10 @@
},
{
"name": "May Day",
"date": "2024-05-01"
"date": "2024-05-03"
},
{
"name": "Founder's Day",
"date": "2024-08-05"
},
{
"name": "Kwame Nkrumah Memorial Day",
"date": "2024-09-23"
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "Constitution Day",
"date": "2024-01-08"
},
{
"name": "Independence Day",
"date": "2024-03-08"
},
{
"name": "Good Friday",
"date": "2024-03-29"
},
{
"name": "Easter Monday",
"date": "2024-04-01"
},
{
"name": "May Day",
"date": "2024-05-03"
},
{
"name": "Founder's Day",
"date": "2024-09-23"
},
{
"name": "Farmers Day",
"date": "2024-12-06"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Boxing Day",
"date": "2024-12-26"
}
]
13 changes: 13 additions & 0 deletions tests/Countries/GhanaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@

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


it('can calculate weekday holidays to friday', function () {
CarbonImmutable::setTestNow('2024-01-01');

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

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

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