diff --git a/src/Countries/Korea.php b/src/Countries/Korea.php new file mode 100644 index 000000000..349982b51 --- /dev/null +++ b/src/Countries/Korea.php @@ -0,0 +1,76 @@ + '01-01', + '3ㆍ1절' => '03-01', + '어린이날' => '05-05', + '현충일' => '06-06', + '광복절' => '08-15', + '개천절' => '10-03', + '한글날' => '10-09', + '크리스마스' => '12-15', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $this->setChineseCalendarTimezone('Asia/Seoul'); + + return array_merge( + $this->getLunarNewYearHoliday($year), + $this->getLunarBuddhasBirthday($year), + $this->getLunarChuseok($year), + ); + } + + /** @return array */ + protected function getLunarNewYearHoliday(int $year): array + { + $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); + + return [ + '설날 연휴 1' => $firstOfJanInChineseCalendar->subDay(), + '설날' => $firstOfJanInChineseCalendar, + '설날 연휴 2' => $firstOfJanInChineseCalendar->addDay(), + ]; + } + + /** @return array */ + protected function getLunarBuddhasBirthday(int $year): array + { + $BuddhasBirthdayInChineseCalendar = $this->chineseToGregorianDate('04-08', $year); + + return [ + '부처님 오신날' => $BuddhasBirthdayInChineseCalendar, + ]; + } + + /** @return array */ + protected function getLunarChuseok(int $year): array + { + $chuseokInChineseCalendar = $this->chineseToGregorianDate('08-15', $year); + + return [ + '추석 연휴 1' => $chuseokInChineseCalendar->subDay(), + '추석' => $chuseokInChineseCalendar, + '추석 연휴 2' => $chuseokInChineseCalendar->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap b/tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap new file mode 100644 index 000000000..b7dc1a0e7 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap @@ -0,0 +1,62 @@ +[ + { + "name": "\uc2e0\uc815", + "date": "2024-01-01" + }, + { + "name": "\uc124\ub0a0 \uc5f0\ud734 1", + "date": "2024-02-09" + }, + { + "name": "\uc124\ub0a0", + "date": "2024-02-10" + }, + { + "name": "\uc124\ub0a0 \uc5f0\ud734 2", + "date": "2024-02-11" + }, + { + "name": "3\u318d1\uc808", + "date": "2024-03-01" + }, + { + "name": "\uc5b4\ub9b0\uc774\ub0a0", + "date": "2024-05-05" + }, + { + "name": "\ubd80\ucc98\ub2d8 \uc624\uc2e0\ub0a0", + "date": "2024-05-15" + }, + { + "name": "\ud604\ucda9\uc77c", + "date": "2024-06-06" + }, + { + "name": "\uad11\ubcf5\uc808", + "date": "2024-08-15" + }, + { + "name": "\ucd94\uc11d \uc5f0\ud734 1", + "date": "2024-09-16" + }, + { + "name": "\ucd94\uc11d", + "date": "2024-09-17" + }, + { + "name": "\ucd94\uc11d \uc5f0\ud734 2", + "date": "2024-09-18" + }, + { + "name": "\uac1c\ucc9c\uc808", + "date": "2024-10-03" + }, + { + "name": "\ud55c\uae00\ub0a0", + "date": "2024-10-09" + }, + { + "name": "\ud06c\ub9ac\uc2a4\ub9c8\uc2a4", + "date": "2024-12-15" + } +] \ No newline at end of file diff --git a/tests/Countries/KoreaTest.php b/tests/Countries/KoreaTest.php new file mode 100644 index 000000000..eeaa9fede --- /dev/null +++ b/tests/Countries/KoreaTest.php @@ -0,0 +1,115 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate the Lunar New Year holiday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNow("{$year}-01-01"); + + $holidays = Holidays::for(country: 'kr')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $lunarNewYearHoliday = array_map(fn($date) => $date['date'], formatDates($holidays)); + + expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); +})->with([ + [ + 'year' => 2024, 'expected_holiday' => [ + '2024-02-09', '2024-02-10', '2024-02-11' + ] + ], + [ + 'year' => 2023, 'expected_holiday' => [ + '2023-01-21', '2023-01-22', '2023-01-23' + ] + ], + [ + 'year' => 2022, 'expected_holiday' => [ + '2022-01-31', '2022-02-01', '2022-02-02' + ] + ], + [ + 'year' => 2021, 'expected_holiday' => [ + '2021-02-11', '2021-02-12', '2021-02-13' + ] + ], + [ + 'year' => 2020, 'expected_holiday' => [ + '2020-01-24', '2020-01-25', '2020-01-26' + ] + ], +]); + +it('can calculate the holiday of Lunar Buddha\'s Birthday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNow("{$year}-01-01"); + + $holidays = Holidays::for(country: 'kr')->get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $dates = array_map(fn($date) => $date['date'], formatDates($holidays)); + + expect($dates)->toContain(...$expectedHoliday); +})->with([ + ['year' => 2024, 'expected_holiday' => ['2024-05-15']], + ['year' => 2023, 'expected_holiday' => ['2023-05-26']], + ['year' => 2022, 'expected_holiday' => ['2022-05-08']] +]); + +it('can calculate the Lunar Chuseok holiday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNow("{$year}-01-01"); + + $holidays = Holidays::for(country: 'kr')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $lunarNewYearHoliday = array_map(fn($date) => $date['date'], formatDates($holidays)); + + expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); +})->with([ + [ + 'year' => 2024, 'expected_holiday' => [ + '2024-09-16', '2024-09-17', '2024-09-18' + ] + ], + [ + 'year' => 2023, 'expected_holiday' => [ + '2023-09-28', '2023-09-29', '2023-09-30' + ] + ], + [ + 'year' => 2022, 'expected_holiday' => [ + '2022-09-09', '2022-09-10', '2022-09-11' + ] + ], + [ + 'year' => 2021, 'expected_holiday' => [ + '2021-09-20', '2021-09-21', '2021-09-22' + ] + ], + [ + 'year' => 2020, 'expected_holiday' => [ + '2020-09-30', '2020-10-01', '2020-10-02' + ] + ] +]);