diff --git a/README.md b/README.md index 92128ddeb..508e61d5b 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,16 @@ use Spatie\Holidays\Holidays; $holidays = Holidays::for(country: 'be', year: 2024))->get(); ``` +### Getting holidays in a specific language + +```php +use Spatie\Holidays\Holidays; + +$holidays = Holidays::for(country: 'be', locale: 'fr'))->get(); +``` + +If the locale is not supported for a country, an exception will be thrown. + ### Determining if a date is a holiday If you need to see if a date is a holiday, you can use the `isHoliday` method. @@ -112,6 +122,7 @@ This is a community driven package. If you find any errors, please create an iss 2. Add a test for the new country in the `tests` directory. 3. Run the tests so a snapshot gets created. 4. Verify the result in the newly created snapshot is correct. +5. If the country has multiple languages, add a file in the `lang/` directory. In case your country has specific rules for calculating holidays, for example region specific holidays, you can pass this to the constructor of your country class. diff --git a/lang/belgium/fr/holidays.json b/lang/belgium/fr/holidays.json new file mode 100644 index 000000000..4232e2d7d --- /dev/null +++ b/lang/belgium/fr/holidays.json @@ -0,0 +1,12 @@ +{ + "Nieuwjaar": "Jour de l'An", + "Dag van de Arbeid": "Fête du Travail", + "Nationale Feestdag": "Fête nationale", + "OLV Hemelvaart": "Assomption", + "Allerheiligen": "Toussaint", + "Wapenstilstand": "Armistice", + "Kerstmis": "Noël", + "Paasmaandag": "Lundi de Pâques", + "OLH Hemelvaart": "Ascension", + "Pinkstermaandag": "Lundi de Pentecôte" +} diff --git a/lang/finland/sv/holidays.json b/lang/finland/sv/holidays.json new file mode 100644 index 000000000..0baa6a4c5 --- /dev/null +++ b/lang/finland/sv/holidays.json @@ -0,0 +1,15 @@ +{ + "Uudenvuodenpäivä": "Nyårsdagen", + "Loppiainen": "Trettondagen", + "Pitkäperjantai": "Långfredagen", + "Pääsiäispäivä": "Påskdagen", + "Toinen pääsiäispäivä": "Annandag påsk", + "Vappu": "Första maj", + "Helatorstai": "Kristi himmelsfärdsdag", + "Helluntaipäivä": "Pingst", + "Juhannuspäivä": "Midsommardagen", + "Pyhäinpäivä": "Alla helgons dag", + "Itsenäisyyspäivä": "Självständighetsdagen", + "Joulupäivä": "Juldagen", + "Tapaninpäivä": "Annandag jul" +} diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php new file mode 100644 index 000000000..0c65b5f7a --- /dev/null +++ b/src/Concerns/Translatable.php @@ -0,0 +1,32 @@ + $data */ + $data = json_decode($content, true); + + if (! isset($data[$name])) { + return $name; + } + + return $data[$name]; + } +} diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php new file mode 100644 index 000000000..f3176f794 --- /dev/null +++ b/src/Countries/Colombia.php @@ -0,0 +1,57 @@ + '01-01', + 'Día del Trabajo' => '05-01', + 'Día de la independencia' => '07-20', + 'Batalla de Boyacá' => '08-07', + 'Inmaculada Concepción' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + 'Ascención de Jesús' => $easter->addDays(43), + 'Corpus Christi' => $easter->addDays(64), + 'Sagrado corazón de Jesús' => $easter->addDays(71), + 'Reyes Magos' => $this->emilianiHoliday($year, 1, 6), + 'Día de San José' => $this->emilianiHoliday($year, 3, 19), + 'San Pedro y San Pablo' => $this->emilianiHoliday($year, 6, 29), + 'Asunción de la Virgen' => $this->emilianiHoliday($year, 8, 15), + 'Día de la raza' => $this->emilianiHoliday($year, 10, 12), + 'Todos los santos' => $this->emilianiHoliday($year, 11, 1), + 'Independencia de Cartagena' => $this->emilianiHoliday($year, 11, 11), + + ]; + } + + private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable + { + $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); + if ($dateObj->is('Monday')) { + return $dateObj; + } else { + return $dateObj->next('Monday'); + } + } +} diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 3a09768db..b6cfab347 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,36 +3,42 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; abstract class Country { + use Translatable; + abstract public function countryCode(): string; /** @return array */ abstract protected function allHolidays(int $year): array; /** @return array */ - public function get(int $year): array + public function get(int $year, ?string $locale = null): array { $this->ensureYearCanBeCalculated($year); $allHolidays = $this->allHolidays($year); - $allHolidays = array_map(function ($date) use ($year) { + $translatedHolidays = []; + foreach ($allHolidays as $name => $date) { if (is_string($date)) { $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); } - return $date; - }, $allHolidays); + $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); + + $translatedHolidays[$name] = $date; + } - uasort($allHolidays, + uasort($translatedHolidays, fn (CarbonImmutable $a, CarbonImmutable $b) => $a->timestamp <=> $b->timestamp ); - return $allHolidays; + return $translatedHolidays; } public static function make(): static diff --git a/src/Countries/ElSalvador.php b/src/Countries/ElSalvador.php new file mode 100644 index 000000000..c3a84a224 --- /dev/null +++ b/src/Countries/ElSalvador.php @@ -0,0 +1,40 @@ + '01-01', + 'Día del Trabajo' => '05-01', + 'Día de la Madre' => '05-10', + 'Día del Padre' => '06-17', + 'Fiesta Divino Salvador del Mundo' => '08-06', + 'Día de la Independencia' => '09-15', + 'Día de Los Difuntos' => '11-02', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/El_Salvador'); + + return [ + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + 'Sábado de Gloria' => $easter->subDays(1), + ]; + } +} diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php new file mode 100644 index 000000000..103fda86f --- /dev/null +++ b/src/Countries/Finland.php @@ -0,0 +1,54 @@ +fixedHolidays($year), $this->variableHolidays($year)); + } + + /** @return array */ + protected function fixedHolidays(int $year): array + { + return [ + 'Uudenvuodenpäivä' => CarbonImmutable::createFromDate($year, 1, 1), + 'Loppiainen' => CarbonImmutable::createFromDate($year, 1, 6), + 'Vappu' => CarbonImmutable::createFromDate($year, 5, 1), + 'Itsenäisyyspäivä' => CarbonImmutable::createFromDate($year, 12, 6), + 'Joulupäivä' => CarbonImmutable::createFromDate($year, 12, 25), + 'Tapaninpäivä' => CarbonImmutable::createFromDate($year, 12, 26), + ]; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Helsinki'); + + $midsummerDay = CarbonImmutable::createFromDate($year, 6, 20) + ->next(CarbonImmutable::SATURDAY); + + return [ + 'Pitkäperjantai' => $easter->subDays(2), + 'Pääsiäispäivä' => $easter, + 'Toinen pääsiäispäivä' => $easter->addDay(), + 'Helatorstai' => $easter->addDays(39), + 'Helluntaipäivä' => $easter->addDays(49), + 'Juhannuspäivä' => $midsummerDay->day > 26 + ? $midsummerDay->subWeek() + : $midsummerDay, + 'Pyhäinpäivä' => CarbonImmutable::createFromDate($year, 10, 31) + ->next(CarbonImmutable::SATURDAY), + ]; + } +} diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php new file mode 100644 index 000000000..38b1bc7d5 --- /dev/null +++ b/src/Countries/Japan.php @@ -0,0 +1,58 @@ + '01-01', // New Year's Day + '建国記念の日' => '02-11', // Foundation Day + '天皇誕生日' => '02-23', // Emperor's Birthday + '春分の日' => '03-20', // Vernal Equinox Day *Decided each year; rarely on 03-21 + '昭和の日' => '04-29', // Showa Day + '憲法記念日' => '05-03', // Constitution Day + 'みどりの日' => '05-04', // Greenery Day + 'こどもの日' => '05-05', // Children's Day + '山の日' => '08-11', // Mountain Day + '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 + '文化の日' => '11-03', // Culture Day + '勤労感謝の日' => '11-23', // Labor Thanksgiving Day + + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $comingOfAgeDay = (new CarbonImmutable("second monday of january $year")) // Coming of Age Day + ->setTimezone('Asia/Tokyo'); + + $oceansDay = (new CarbonImmutable("third monday of july $year")) // Ocean's Day + ->setTimezone('Asia/Tokyo'); + + $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year")) // Respect for the Aged Day + ->setTimezone('Asia/Tokyo'); + + $sportsDay = (new CarbonImmutable("second monday of october $year")) // Sports Day + ->setTimezone('Asia/Tokyo'); + + $holidays = [ + '成人の日' => $comingOfAgeDay, + '海の日' => $oceansDay, + '敬老の日' => $respectForTheAgedDay, + 'スポーツの日' => $sportsDay, + ]; + + return $holidays; + + } +} diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php new file mode 100644 index 000000000..b5c088605 --- /dev/null +++ b/src/Countries/Latvia.php @@ -0,0 +1,63 @@ + '01-01', + 'Darba svētki' => '05-01', + 'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena' => '05-04', + 'Līgo diena' => '06-23', + 'Jāņu diena' => '06-24', + 'Latvijas Republikas proklamēšanas diena' => '11-18', + 'Ziemassvētku vakars' => '12-24', + 'Pirmie Ziemassvētki' => '12-25', + 'Otrie Ziemassvētki' => '12-26', + 'Vecgada vakars' => '12-31', + ], $this->variableHolidays($year), $this->postponedHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Lielā Piektdiena' => $easter->subDays(2), + 'Pirmās Lieldienas' => $easter, + 'Otrās Lieldienas' => $easter->addDay(), + ]; + } + + /** @return array */ + protected function postponedHolidays(int $year): array + { + // If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, + // the next working day is designated as a holiday. + $holidays = []; + + $date = new CarbonImmutable(); + + $date = $date->setDate($year, 5, 4); + if ($date->isWeekend()) { + $holidays['Pārceltā 4. maija brīvdiena'] = $date->nextWeekday()->format('m-d'); + } + + $date = $date->setDate($year, 11, 18); + if ($date->isWeekend()) { + $holidays['Pārceltā 18. novembra brīvdiena'] = $date->nextWeekday()->format('m-d'); + } + + return $holidays; + } +} diff --git a/src/Countries/Serbia.php b/src/Countries/Serbia.php new file mode 100644 index 000000000..117885062 --- /dev/null +++ b/src/Countries/Serbia.php @@ -0,0 +1,39 @@ + '01-01', + 'Nova godina - drugi dan' => '01-02', + 'Božić' => '01-07', + 'Dan državnosti - prvi dan' => '02-15', + 'Dan državnosti - drugi dan' => '02-16', + 'Praznik rada - prvi dan' => '05-01', + 'Praznik rada - drugi dan' => '05-02', + 'Dan primirja u Prvom svetskom ratu' => '11-11', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->orthodoxEaster($year); + + return [ + 'Veliki petak' => $easter->subDays(2), + 'Vaskrs' => $easter, + 'Vaskršnji ponedeljak' => $easter->addDay(), + ]; + } +} diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php new file mode 100644 index 000000000..32d21dccb --- /dev/null +++ b/src/Countries/Slovakia.php @@ -0,0 +1,43 @@ + '01-01', + 'Zjavenie Pána (Traja králi)' => '01-06', + 'Sviatok práce' => '05-01', + 'Deň víťazstva nad fašizmom' => '05-08', + 'Sviatok svätého Cyrila a Metoda' => '07-05', + 'Výročie Slovenského národného povstania' => '08-29', + 'Deň Ústavy Slovenskej republiky' => '09-01', + 'Sedembolestná Panna Mária' => '09-15', + 'Sviatok všetkých svätých' => '11-01', + 'Deň boja za slobodu a demokraciu' => '11-17', + 'Štedrý deň' => '12-24', + 'Prvý sviatok vianočný' => '12-25', + 'Druhý sviatok vianočný' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Veľkonočný pondelok' => $easter->addDay(), + 'Veľký piatok' => $easter->subDays(2), + ]; + } +} diff --git a/src/Countries/UnitedStates.php b/src/Countries/UnitedStates.php new file mode 100644 index 000000000..695103dca --- /dev/null +++ b/src/Countries/UnitedStates.php @@ -0,0 +1,49 @@ + '01-01', + 'Independence Day' => '07-04', + 'Veterans Day' => '11-11', + 'Christmas' => '12-25', + ], $this->variableHolidays($year)); + + if ($year >= 2021) { + $holidays['Juneteenth National Independence Day'] = '06-19'; + } + + return $holidays; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $martinLutherKingDay = new CarbonImmutable("third monday of January $year", 'America/Los_Angeles'); + $presidentsDay = new CarbonImmutable("third monday of February $year", 'America/Los_Angeles'); + $memorialDay = new CarbonImmutable("last monday of May $year", 'America/Los_Angeles'); + $laborDay = new CarbonImmutable("first monday of September $year", 'America/Los_Angeles'); + $columbusDay = new CarbonImmutable("second monday of October $year", 'America/Los_Angeles'); + $thanksgiving = new CarbonImmutable("fourth thursday of November $year", 'America/Los_Angeles'); + + return [ + 'Martin Luther King Day' => $martinLutherKingDay, + 'Presidents\' Day' => $presidentsDay, + 'Memorial Day' => $memorialDay, + 'Labor Day' => $laborDay, + 'Columbus Day' => $columbusDay, + 'Thanksgiving' => $thanksgiving, + ]; + } +} diff --git a/src/Exceptions/InvalidLocale.php b/src/Exceptions/InvalidLocale.php new file mode 100644 index 000000000..1d34fc8d3 --- /dev/null +++ b/src/Exceptions/InvalidLocale.php @@ -0,0 +1,13 @@ +year; @@ -25,12 +26,12 @@ public static function for(Country|string $country, ?int $year = null): static $country = Country::findOrFail($country); } - return new static($country, $year); + return new static($country, $year, $locale); } public static function has(string $country): bool { - return Country::find($country) instanceof Country; + return Country::find($country) !== null; } /** @return array */ @@ -39,7 +40,7 @@ public function get(Country|string|null $country = null, ?int $year = null): arr $country ??= $this->country; $year ??= $this->year; - return static::for($country, $year) + return static::for($country, $year, $this->locale) ->calculate() ->toArray(); } @@ -91,7 +92,7 @@ public function getName(CarbonInterface|string $date, Country|string|null $count protected function calculate(): self { - $this->holidays = $this->country->get($this->year); + $this->holidays = $this->country->get($this->year, $this->locale); return $this; } diff --git a/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap new file mode 100644 index 000000000..38e611c25 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap @@ -0,0 +1,74 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Reyes Magos", + "date": "2024-01-08" + }, + { + "name": "D\u00eda de San Jos\u00e9", + "date": "2024-03-25" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "Ascenci\u00f3n de Jes\u00fas", + "date": "2024-05-13" + }, + { + "name": "Corpus Christi", + "date": "2024-06-03" + }, + { + "name": "Sagrado coraz\u00f3n de Jes\u00fas", + "date": "2024-06-10" + }, + { + "name": "San Pedro y San Pablo", + "date": "2024-07-01" + }, + { + "name": "D\u00eda de la independencia", + "date": "2024-07-20" + }, + { + "name": "Batalla de Boyac\u00e1", + "date": "2024-08-07" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-19" + }, + { + "name": "D\u00eda de la raza", + "date": "2024-10-14" + }, + { + "name": "Todos los santos", + "date": "2024-11-04" + }, + { + "name": "Independencia de Cartagena", + "date": "2024-11-11" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap b/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap new file mode 100644 index 000000000..2586f7686 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Jueves Santo", + "date": "2024-03-27" + }, + { + "name": "Viernes Santo", + "date": "2024-03-28" + }, + { + "name": "S\u00e1bado de Gloria", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de la Madre", + "date": "2024-05-10" + }, + { + "name": "D\u00eda del Padre", + "date": "2024-06-17" + }, + { + "name": "Fiesta Divino Salvador del Mundo", + "date": "2024-08-06" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-09-15" + }, + { + "name": "D\u00eda de Los Difuntos", + "date": "2024-11-02" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap b/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap new file mode 100644 index 000000000..8a4f7a954 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Uudenvuodenp\u00e4iv\u00e4", + "date": "2024-01-01" + }, + { + "name": "Loppiainen", + "date": "2024-01-06" + }, + { + "name": "Pitk\u00e4perjantai", + "date": "2024-03-29" + }, + { + "name": "P\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", + "date": "2024-03-31" + }, + { + "name": "Toinen p\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", + "date": "2024-04-01" + }, + { + "name": "Vappu", + "date": "2024-05-01" + }, + { + "name": "Helatorstai", + "date": "2024-05-09" + }, + { + "name": "Helluntaip\u00e4iv\u00e4", + "date": "2024-05-19" + }, + { + "name": "Juhannusp\u00e4iv\u00e4", + "date": "2024-06-22" + }, + { + "name": "Pyh\u00e4inp\u00e4iv\u00e4", + "date": "2024-11-02" + }, + { + "name": "Itsen\u00e4isyysp\u00e4iv\u00e4", + "date": "2024-12-06" + }, + { + "name": "Joulup\u00e4iv\u00e4", + "date": "2024-12-25" + }, + { + "name": "Tapaninp\u00e4iv\u00e4", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap b/tests/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap new file mode 100644 index 000000000..7f852ccd4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Ny\u00e5rsdagen", + "date": "2024-01-01" + }, + { + "name": "Trettondagen", + "date": "2024-01-06" + }, + { + "name": "L\u00e5ngfredagen", + "date": "2024-03-29" + }, + { + "name": "P\u00e5skdagen", + "date": "2024-03-31" + }, + { + "name": "Annandag p\u00e5sk", + "date": "2024-04-01" + }, + { + "name": "F\u00f6rsta maj", + "date": "2024-05-01" + }, + { + "name": "Kristi himmelsf\u00e4rdsdag", + "date": "2024-05-09" + }, + { + "name": "Pingst", + "date": "2024-05-19" + }, + { + "name": "Midsommardagen", + "date": "2024-06-22" + }, + { + "name": "Alla helgons dag", + "date": "2024-11-02" + }, + { + "name": "Sj\u00e4lvst\u00e4ndighetsdagen", + "date": "2024-12-06" + }, + { + "name": "Juldagen", + "date": "2024-12-25" + }, + { + "name": "Annandag jul", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap b/tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap new file mode 100644 index 000000000..5d86d702a --- /dev/null +++ b/tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "\u5143\u65e5", + "date": "2024-01-01" + }, + { + "name": "\u6210\u4eba\u306e\u65e5", + "date": "2024-01-08" + }, + { + "name": "\u5efa\u56fd\u8a18\u5ff5\u306e\u65e5", + "date": "2024-02-11" + }, + { + "name": "\u5929\u7687\u8a95\u751f\u65e5", + "date": "2024-02-23" + }, + { + "name": "\u6625\u5206\u306e\u65e5", + "date": "2024-03-20" + }, + { + "name": "\u662d\u548c\u306e\u65e5", + "date": "2024-04-29" + }, + { + "name": "\u61b2\u6cd5\u8a18\u5ff5\u65e5", + "date": "2024-05-03" + }, + { + "name": "\u307f\u3069\u308a\u306e\u65e5", + "date": "2024-05-04" + }, + { + "name": "\u3053\u3069\u3082\u306e\u65e5", + "date": "2024-05-05" + }, + { + "name": "\u6d77\u306e\u65e5", + "date": "2024-07-15" + }, + { + "name": "\u5c71\u306e\u65e5", + "date": "2024-08-11" + }, + { + "name": "\u656c\u8001\u306e\u65e5", + "date": "2024-09-16" + }, + { + "name": "\u79cb\u5206\u306e\u65e5", + "date": "2024-09-23" + }, + { + "name": "\u30b9\u30dd\u30fc\u30c4\u306e\u65e5", + "date": "2024-10-14" + }, + { + "name": "\u6587\u5316\u306e\u65e5", + "date": "2024-11-03" + }, + { + "name": "\u52e4\u52b4\u611f\u8b1d\u306e\u65e5", + "date": "2024-11-23" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap b/tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap new file mode 100644 index 000000000..efe1c19fc --- /dev/null +++ b/tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "Jaunais gads", + "date": "2024-01-01" + }, + { + "name": "Liel\u0101 Piektdiena", + "date": "2024-03-29" + }, + { + "name": "Pirm\u0101s Lieldienas", + "date": "2024-03-31" + }, + { + "name": "Otr\u0101s Lieldienas", + "date": "2024-04-01" + }, + { + "name": "Darba sv\u0113tki", + "date": "2024-05-01" + }, + { + "name": "Latvijas Republikas Neatkar\u012bbas deklar\u0101cijas pasludin\u0101\u0161anas diena", + "date": "2024-05-04" + }, + { + "name": "P\u0101rcelt\u0101 4. maija br\u012bvdiena", + "date": "2024-05-06" + }, + { + "name": "L\u012bgo diena", + "date": "2024-06-23" + }, + { + "name": "J\u0101\u0146u diena", + "date": "2024-06-24" + }, + { + "name": "Latvijas Republikas proklam\u0113\u0161anas diena", + "date": "2024-11-18" + }, + { + "name": "Ziemassv\u0113tku vakars", + "date": "2024-12-24" + }, + { + "name": "Pirmie Ziemassv\u0113tki", + "date": "2024-12-25" + }, + { + "name": "Otrie Ziemassv\u0113tki", + "date": "2024-12-26" + }, + { + "name": "Vecgada vakars", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap b/tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap new file mode 100644 index 000000000..09b207302 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Nova godina - prvi dan", + "date": "2024-01-01" + }, + { + "name": "Nova godina - drugi dan", + "date": "2024-01-02" + }, + { + "name": "Bo\u017ei\u0107", + "date": "2024-01-07" + }, + { + "name": "Dan dr\u017eavnosti - prvi dan", + "date": "2024-02-15" + }, + { + "name": "Dan dr\u017eavnosti - drugi dan", + "date": "2024-02-16" + }, + { + "name": "Praznik rada - prvi dan", + "date": "2024-05-01" + }, + { + "name": "Praznik rada - drugi dan", + "date": "2024-05-02" + }, + { + "name": "Veliki petak", + "date": "2024-05-03" + }, + { + "name": "Vaskrs", + "date": "2024-05-05" + }, + { + "name": "Vaskr\u0161nji ponedeljak", + "date": "2024-05-06" + }, + { + "name": "Dan primirja u Prvom svetskom ratu", + "date": "2024-11-11" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap new file mode 100644 index 000000000..ac07602fd --- /dev/null +++ b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap @@ -0,0 +1,62 @@ +[ + { + "name": "De\u0148 vzniku Slovenskej republiky", + "date": "2024-01-01" + }, + { + "name": "Zjavenie P\u00e1na (Traja kr\u00e1li)", + "date": "2024-01-06" + }, + { + "name": "Ve\u013ek\u00fd piatok", + "date": "2024-03-29" + }, + { + "name": "Ve\u013ekono\u010dn\u00fd pondelok", + "date": "2024-04-01" + }, + { + "name": "Sviatok pr\u00e1ce", + "date": "2024-05-01" + }, + { + "name": "De\u0148 v\u00ed\u0165azstva nad fa\u0161izmom", + "date": "2024-05-08" + }, + { + "name": "Sviatok sv\u00e4t\u00e9ho Cyrila a Metoda", + "date": "2024-07-05" + }, + { + "name": "V\u00fdro\u010die Slovensk\u00e9ho n\u00e1rodn\u00e9ho povstania", + "date": "2024-08-29" + }, + { + "name": "De\u0148 \u00dastavy Slovenskej republiky", + "date": "2024-09-01" + }, + { + "name": "Sedembolestn\u00e1 Panna M\u00e1ria", + "date": "2024-09-15" + }, + { + "name": "Sviatok v\u0161etk\u00fdch sv\u00e4t\u00fdch", + "date": "2024-11-01" + }, + { + "name": "De\u0148 boja za slobodu a demokraciu", + "date": "2024-11-17" + }, + { + "name": "\u0160tedr\u00fd de\u0148", + "date": "2024-12-24" + }, + { + "name": "Prv\u00fd sviatok viano\u010dn\u00fd", + "date": "2024-12-25" + }, + { + "name": "Druh\u00fd sviatok viano\u010dn\u00fd", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap new file mode 100644 index 000000000..41227b5c4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Martin Luther King Day", + "date": "2024-01-15" + }, + { + "name": "Presidents' Day", + "date": "2024-02-19" + }, + { + "name": "Memorial Day", + "date": "2024-05-27" + }, + { + "name": "Juneteenth National Independence Day", + "date": "2024-06-19" + }, + { + "name": "Independence Day", + "date": "2024-07-04" + }, + { + "name": "Labor Day", + "date": "2024-09-02" + }, + { + "name": "Columbus Day", + "date": "2024-10-14" + }, + { + "name": "Veterans Day", + "date": "2024-11-11" + }, + { + "name": "Thanksgiving", + "date": "2024-11-28" + }, + { + "name": "Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap new file mode 100644 index 000000000..5d92494f7 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Martin Luther King Day", + "date": "2020-01-20" + }, + { + "name": "Presidents' Day", + "date": "2020-02-17" + }, + { + "name": "Memorial Day", + "date": "2020-05-25" + }, + { + "name": "Independence Day", + "date": "2020-07-04" + }, + { + "name": "Labor Day", + "date": "2020-09-07" + }, + { + "name": "Columbus Day", + "date": "2020-10-12" + }, + { + "name": "Veterans Day", + "date": "2020-11-11" + }, + { + "name": "Thanksgiving", + "date": "2020-11-26" + }, + { + "name": "Christmas", + "date": "2020-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ColombiaTest.php b/tests/Countries/ColombiaTest.php new file mode 100644 index 000000000..623ffd94b --- /dev/null +++ b/tests/Countries/ColombiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/ElSalvadorTest.php b/tests/Countries/ElSalvadorTest.php new file mode 100644 index 000000000..892a8f791 --- /dev/null +++ b/tests/Countries/ElSalvadorTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/FinlandTest.php b/tests/Countries/FinlandTest.php new file mode 100644 index 000000000..565dc1623 --- /dev/null +++ b/tests/Countries/FinlandTest.php @@ -0,0 +1,32 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('can get finnish holidays in swedish', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'fi', locale: 'sv')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); diff --git a/tests/Countries/JapanTest.php b/tests/Countries/JapanTest.php new file mode 100644 index 000000000..3a948815e --- /dev/null +++ b/tests/Countries/JapanTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/LatviaTest.php b/tests/Countries/LatviaTest.php new file mode 100644 index 000000000..bce7acb68 --- /dev/null +++ b/tests/Countries/LatviaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/SerbiaTest.php b/tests/Countries/SerbiaTest.php new file mode 100644 index 000000000..1a44fbb44 --- /dev/null +++ b/tests/Countries/SerbiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/SlovakiaTest.php b/tests/Countries/SlovakiaTest.php new file mode 100644 index 000000000..cb08ebd5a --- /dev/null +++ b/tests/Countries/SlovakiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/UnitedStatesTest.php b/tests/Countries/UnitedStatesTest.php new file mode 100644 index 000000000..bdf277d2f --- /dev/null +++ b/tests/Countries/UnitedStatesTest.php @@ -0,0 +1,32 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('can calculate united states holidays before 2021', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'us')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index aa242162b..c09d7db67 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -3,6 +3,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Belgium; use Spatie\Holidays\Countries\Netherlands; +use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; use Spatie\Holidays\Holidays; @@ -91,3 +92,14 @@ $result = Holidays::has(country: 'unknown'); expect($result)->toBeFalse(); }); + +it('can get translated holiday names', function () { + $result = Holidays::for(country: 'be', year: 2020, locale: 'fr')->get(); + + expect($result)->toBeArray(); + expect($result[0]['name'])->toBe('Jour de l\'An'); +}); + +it('cannot get translated holiday names for unsupported locales', function () { + Holidays::for(country: 'be', year: 2020, locale: 'en')->get(); +})->throws(InvalidLocale::class, 'Locale `en` is not supported for country `Belgium`.');