diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php new file mode 100644 index 00000000..c7efc9e2 --- /dev/null +++ b/src/Countries/Canada.php @@ -0,0 +1,61 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge( + [ + 'New Year\'s Day' => new CarbonImmutable($year . "-01-01", 'America/Toronto'), + 'Canada Day' => new CarbonImmutable($year . "-07-01", 'America/Toronto'), + 'Civic Holiday' => new CarbonImmutable( + "first monday of August " . $year, 'America/Toronto' + ), + 'Labour Day' => new CarbonImmutable( + "first monday of September " . $year, 'America/Toronto' + ), + 'National Day for Truth and Reconciliation' => new CarbonImmutable( + $year . "-09-30", + 'America/Toronto' + ), + 'Remembrance Day' => new CarbonImmutable($year . "-11-11", 'America/Toronto'), + 'Christmas Day' => new CarbonImmutable($year . "-12-25", 'America/Toronto'), + 'Boxing Day' => new CarbonImmutable($year . '-12-26', 'America/Toronto'), + ], + $this->variableHolidays($year) + ); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Toronto'); + + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDays(1); + + $victoriaDay = new CarbonImmutable("last monday of May $year", 'America/Toronto'); + if ($victoriaDay->day < 25) { + $victoriaDay = $victoriaDay->addWeek(); + } + + $thanksgiving = new CarbonImmutable("second monday of October $year", 'America/Toronto'); + return [ + 'Victoria Day' => $victoriaDay, + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + 'Thanksgiving' => $thanksgiving, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap b/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap new file mode 100644 index 00000000..3168b8ea --- /dev/null +++ b/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Victoria Day", + "date": "2024-05-27" + }, + { + "name": "Canada Day", + "date": "2024-07-01" + }, + { + "name": "Civic Holiday", + "date": "2024-08-05" + }, + { + "name": "Labour Day", + "date": "2024-09-02" + }, + { + "name": "National Day for Truth and Reconciliation", + "date": "2024-09-30" + }, + { + "name": "Thanksgiving", + "date": "2024-10-14" + }, + { + "name": "Remembrance Day", + "date": "2024-11-11" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/CanadaTest.php b/tests/Countries/CanadaTest.php new file mode 100644 index 00000000..0619c4ec --- /dev/null +++ b/tests/Countries/CanadaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});