generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'spatie:main' into main
- Loading branch information
Showing
34 changed files
with
1,236 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Concerns; | ||
|
||
use Spatie\Holidays\Exceptions\InvalidLocale; | ||
|
||
trait Translatable | ||
{ | ||
protected function translate(string $country, string $name, ?string $locale = null): string | ||
{ | ||
if ($locale === null) { | ||
return $name; | ||
} | ||
|
||
$countryName = strtolower($country); | ||
|
||
$content = file_get_contents(__DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"); | ||
|
||
if ($content === false) { | ||
throw InvalidLocale::notFound($country, $locale); | ||
} | ||
|
||
/** @var array<string, string> $data */ | ||
$data = json_decode($content, true); | ||
|
||
if (! isset($data[$name])) { | ||
return $name; | ||
} | ||
|
||
return $data[$name]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Colombia extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'co'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Año Nuevo' => '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<string, CarbonImmutable> */ | ||
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'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class ElSalvador extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'sv'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Año Nuevo' => '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<string, CarbonImmutable> */ | ||
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), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Finland extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'fi'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge($this->fixedHolidays($year), $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
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), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Japan extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'jp'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'元日' => '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<string, CarbonImmutable> */ | ||
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; | ||
|
||
} | ||
} |
Oops, something went wrong.