generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Spanish Holidays #34
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
199d8f6
Add Spanish Holidays
jaltez 3688abe
Merge branch 'spatie:main' into main
jaltez cd5a924
Holidays added by region for the current year.
jaltez 675f817
Regional holidays: 2023, 2022
jaltez 97c2bfa
Variable naming as holidays.
jaltez 1f55b31
Merge branch 'spatie:main' into main
jaltez 4ffe3fa
Added exceptions and null region check.
jaltez 73c0e00
Merge branch 'spatie:main' into main
jaltez c8b9a43
Change to custom exceptions.
jaltez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,388 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Spain extends Country | ||
{ | ||
protected function __construct( | ||
protected ?string $region = null, | ||
) { | ||
} | ||
|
||
public function countryCode(): string | ||
{ | ||
return 'es'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge( | ||
[ | ||
'Año Nuevo' => '01-01', | ||
'Epifanía del Señor' => '01-06', | ||
'Día del Trabajador' => '05-01', | ||
'Asunción de la Virgen' => '08-15', | ||
'Fiesta Nacional de España' => '10-12', | ||
'Todos los Santos' => '11-01', | ||
'Día de la Constitución Española' => '12-06', | ||
'Inmaculada Concepción' => '12-08', // 2024? | ||
'Navidad' => '12-25' | ||
], | ||
$this->variableHolidays($year), | ||
$this->regionHolidays($year), | ||
); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Viernes Santo' => $easter->subDays(2), | ||
]; | ||
} | ||
|
||
/** @return array<string, string> */ | ||
protected function regionHolidays(int $year): array | ||
{ | ||
$method = "regionHolidays{$year}"; | ||
if (method_exists($this, $method)) { | ||
return $this->$method(); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
/** @return array<string, string> */ | ||
protected function regionHolidays2022(): array | ||
{ | ||
$juevesSanto = ['Jueves Santo' => '04-14']; | ||
$lunesPascua = ['Lunes de Pascua' => '04-18']; | ||
$fiestaTrabajo = ['Lunes siguiente a la Fiesta del Trabajo' => '05-02']; | ||
$sanJuan = ['San Juan' => '06-24']; | ||
$santiagoApostol = ['Santiago Apóstol' => '07-25']; | ||
$navidad = ['Lunes siguiente a Navidad' => '12-26']; | ||
|
||
return match ($this->region) { | ||
// Andalucía | ||
'es-an' => [ | ||
'Día de Andalucía' => '02-28', | ||
] + $juevesSanto + $fiestaTrabajo + $navidad, | ||
|
||
// Aragón | ||
'es-ar' => [ | ||
'Lunes siguiente a San Jorge, Día de Aragón' => '04-23', | ||
] + $juevesSanto + $fiestaTrabajo + $navidad, | ||
|
||
// Principado de Asturias | ||
'es-as' => [ | ||
'Día de Asturias' => '09-08', | ||
] + $juevesSanto + $fiestaTrabajo + $navidad, | ||
|
||
// Cantabria | ||
'es-cb' => [ | ||
'Día de las Instituciones de Cantabria' => '07-28', | ||
'La Bien Aparecida' => '09-15', | ||
] + $juevesSanto + $navidad, | ||
|
||
// Ciudad Autónoma de Ceuta | ||
'es-ce' => [ | ||
'Fiesta del Sacrificio Eid al-Adha' => '07-09', | ||
'Nuestra Señora de África' => '08-05', | ||
'Día de Ceuta' => '09-02', | ||
] + $juevesSanto, | ||
|
||
// Castilla y León | ||
'es-cl' => [ | ||
'Día de Castilla y León' => '04-23', | ||
] + $juevesSanto + $fiestaTrabajo + $navidad, | ||
|
||
// Castilla-La Mancha | ||
'es-cm' => [ | ||
'Día de Castilla-La Mancha' => '05-31', | ||
'Corpus Christi' => '06-16', | ||
] + $juevesSanto + $navidad, | ||
|
||
// Canarias | ||
'es-cn' => [ | ||
'Día de Canarias' => '05-30', | ||
] + $juevesSanto + $navidad, | ||
|
||
// Cataluña / Catalunya | ||
'es-ct' => [ | ||
'Pascua Granada' => '06-06', | ||
] + $lunesPascua + $sanJuan + $navidad, | ||
|
||
// Extremadura | ||
'es-ex' => [ | ||
'Día de Extremadura' => '09-08', | ||
] + $juevesSanto + $fiestaTrabajo + $navidad, | ||
|
||
// Galicia | ||
'es-ga' => [ | ||
'Día de las Letras Gallegas' => '05-17', | ||
'Santiago Apóstol / Día de Galicia' => '07-25', | ||
] + $juevesSanto + $sanJuan, | ||
|
||
// Islas Baleares / Illes Balears | ||
'es-ib' => [ | ||
'Día de les Illes Balears' => '03-01', | ||
] + $juevesSanto + $lunesPascua + $navidad, | ||
|
||
// Región de Murcia | ||
'es-mc' => [ | ||
'Día de la Región de Murcia' => '06-09', | ||
] + $juevesSanto + $fiestaTrabajo + $navidad, | ||
|
||
// Comunidad de Madrid | ||
'es-md' => [ | ||
'Fiesta de la Comunidad de Madrid' => '05-02', | ||
] + $juevesSanto + $santiagoApostol + $navidad, | ||
|
||
// Ciudad Autónoma de Melilla | ||
'es-ml' => [ | ||
'Fiesta del Eid al-Fitr' => '05-03', | ||
'Fiesta del Sacrificio Eid al-Adha' => '07-11' | ||
] + $juevesSanto + $navidad, | ||
|
||
// Comunidad Foral de Navarra / Nafarroako Foru Komunitatea | ||
'es-nc' => $juevesSanto + $lunesPascua + $santiagoApostol + $navidad, | ||
|
||
// País Vasco / Euskal Herria | ||
'es-pv' => [ | ||
'V Centenario de la Primera Vuelta al Mundo' => '09-06', | ||
] + $juevesSanto + $lunesPascua + $santiagoApostol, | ||
|
||
// La Rioja | ||
'es-ri' => [ | ||
'Día de La Rioja' => '06-09', | ||
] + $juevesSanto + $lunesPascua + $navidad, | ||
|
||
// Comunidad Valenciana / Comunitat Valenciana | ||
'es-vc' => [ | ||
'Día de la Comunidad Valenciana' => '10-09', | ||
'San José' => '03-19', | ||
] + $juevesSanto + $lunesPascua + $sanJuan, | ||
|
||
default => [], | ||
}; | ||
} | ||
|
||
/** @return array<string, string> */ | ||
protected function regionHolidays2023(): array | ||
{ | ||
$anoNuevo = ['Lunes siguiente a la Fiesta de Año Nuevo' => '01-02']; | ||
$jueveSanto = ['Jueves Santo' => '04-06']; | ||
$lunesPascua = ['Lunes de Pascua' => '04-10']; | ||
$sanJuan = ['San Juan' => '06-24']; | ||
$fiestaSacrificio = ['Fiesta del Sacrificio Eid al-Adha' => '06-29']; | ||
$santiagoApostol = ['Santiago Apóstol' => '07-25']; | ||
|
||
return match ($this->region) { | ||
// Andalucía | ||
'es-an' => [ | ||
'Día de Andalucía' => '02-28', | ||
] + $anoNuevo + $jueveSanto, | ||
|
||
// Aragón | ||
'es-ar' => [ | ||
'Lunes siguiente a San Jorge, Día de Aragón' => '04-24', | ||
] + $anoNuevo + $jueveSanto, | ||
|
||
// Principado de Asturias | ||
'es-as' => [ | ||
'Día de Asturias' => '09-08', | ||
] + $anoNuevo + $jueveSanto, | ||
|
||
// Cantabria | ||
'es-cb' => [ | ||
'Día de las Instituciones de Cantabria' => '07-28', | ||
'La Bien Aparecida' => '09-15', | ||
] + $jueveSanto, | ||
|
||
// Ciudad Autónoma de Ceuta | ||
'es-ce' => [ | ||
'Nuestra Señora de África' => '08-05', | ||
'Día de Ceuta' => '09-02', | ||
] + $jueveSanto + $fiestaSacrificio, | ||
|
||
// Castilla y León | ||
'es-cl' => $anoNuevo + $jueveSanto + $santiagoApostol, | ||
|
||
// Castilla-La Mancha | ||
'es-cm' => [ | ||
'Día de Castilla-La Mancha' => '05-31', | ||
'Corpus Christi' => '06-08', | ||
] + $jueveSanto, | ||
|
||
// Canarias | ||
'es-cn' => [ | ||
'Día de Canarias' => '05-30', | ||
] + $jueveSanto, | ||
|
||
// Cataluña / Catalunya | ||
'es-ct' => [ | ||
'Fiesta Nacional de Cataluña' => '09-11', | ||
'San Esteban' => '12-26', | ||
] + $lunesPascua + $sanJuan, | ||
|
||
// Extremadura | ||
'es-ex' => [ | ||
'Carnaval' => '02-13', | ||
'Día de Extremadura' => '09-08', | ||
] + $jueveSanto, | ||
|
||
// Galicia | ||
'es-ga' => [ | ||
'Día de las Letras Gallegas' => '05-17', | ||
'Santiago Apóstol / Día de Galicia' => '07-25', | ||
] + $jueveSanto, | ||
|
||
// Islas Baleares / Illes Balears | ||
'es-ib' => [ | ||
'Día de les Illes Balears' => '03-01', | ||
] + $lunesPascua, | ||
|
||
// Región de Murcia | ||
'es-mc' => [ | ||
'Día de la Región de Murcia' => '06-09', | ||
] + $anoNuevo + $jueveSanto, | ||
|
||
// Comunidad de Madrid | ||
'es-md' => [ | ||
'Lunes siguiente A San José' => '03-20', | ||
'Fiesta de la Comunidad de Madrid' => '05-02', | ||
] + $jueveSanto, | ||
|
||
// Ciudad Autónoma de Melilla | ||
'es-ml' => [ | ||
'Fiesta del Eid al-Fitr' => '04-21', | ||
] + $jueveSanto + $fiestaSacrificio, | ||
|
||
// Comunidad Foral de Navarra / Nafarroako Foru Komunitatea | ||
'es-nc' => $jueveSanto + $lunesPascua + $santiagoApostol, | ||
|
||
// País Vasco / Euskal Herria | ||
'es-pv' => $jueveSanto + $lunesPascua + $santiagoApostol, | ||
|
||
// La Rioja | ||
'es-ri' => [ | ||
'Día de La Rioja' => '06-09', | ||
] + $jueveSanto + $lunesPascua, | ||
|
||
// Comunidad Valenciana / Comunitat Valenciana | ||
'es-vc' => [ | ||
'Día de la Comunidad Valenciana' => '10-09', | ||
] + $lunesPascua + $sanJuan, | ||
|
||
default => [], | ||
}; | ||
} | ||
|
||
/** @return array<string, string> */ | ||
protected function regionHolidays2024(): array | ||
{ | ||
$sanJose = ['San José' => '03-19']; | ||
$juevesSanto = ['Jueves Santo' => '03-28']; | ||
$lunesPascua = ['Lunes de Pascua' => '04-01']; | ||
$fiestaSacrificio = ['Fiesta del Sacrificio Eid al-Adha' => '06-17']; | ||
$sanJuan = ['San Juan' => '06-24']; | ||
$santiagoApostol = ['Santiago Apóstol' => '07-25']; | ||
$inmaculadaConcepcion = ['Lunes siguiente a la Inmaculada Concepción' => '12-09']; | ||
|
||
return match ($this->region) { | ||
// Andalucía | ||
'es-an' => [ | ||
'Día de Andalucía' => '02-28', | ||
] + $juevesSanto + $inmaculadaConcepcion, | ||
|
||
// Aragón | ||
'es-ar' => [ | ||
'San Jorge / Día de Aragón' => '04-23', | ||
] + $juevesSanto + $inmaculadaConcepcion, | ||
|
||
// Principado de Asturias | ||
'es-as' => [ | ||
'Lunes siguiente al Día de Asturias' => '09-09', | ||
] + $juevesSanto + $inmaculadaConcepcion, | ||
|
||
// Cantabria | ||
'es-cb' => $juevesSanto + $lunesPascua + $santiagoApostol, | ||
|
||
// Ciudad Autónoma de Ceuta | ||
'es-ce' => [ | ||
'Nuestra Señora de África' => '08-05', | ||
] + $juevesSanto + $fiestaSacrificio, | ||
|
||
// Castilla y León | ||
'es-cl' => [ | ||
'Fiesta de Castilla y León' => '04-23', | ||
] + $juevesSanto + $inmaculadaConcepcion, | ||
|
||
// Castilla-La Mancha | ||
'es-cm' => [ | ||
'Corpus Christi' => '05-30', | ||
'Día de Castilla-La Mancha' => '05-31', | ||
] + $juevesSanto, | ||
|
||
// Canarias | ||
'es-cn' => [ | ||
'Día de Canarias' => '05-30', | ||
] + $juevesSanto, | ||
|
||
// Cataluña / Catalunya | ||
'es-ct' => [ | ||
'Fiesta Nacional de Cataluña' => '09-11', | ||
'San Esteban' => '12-26', | ||
] + $lunesPascua + $sanJuan, | ||
|
||
// Extremadura | ||
'es-ex' => [ | ||
'Carnaval' => '02-13', | ||
] + $juevesSanto + $inmaculadaConcepcion, | ||
|
||
// Galicia | ||
'es-ga' => [ | ||
'Día de las Letras Gallegas' => '05-17', | ||
'Santiago Apóstol / Día de Galicia' => '07-25', | ||
] + $juevesSanto, | ||
|
||
// Islas Baleares / Illes Balears | ||
'es-ib' => [ | ||
'Día de les Illes Balears' => '03-01', | ||
] + $juevesSanto + $lunesPascua, | ||
|
||
// Región de Murcia | ||
'es-mc' => $sanJose + $juevesSanto + $inmaculadaConcepcion, | ||
|
||
// Comunidad de Madrid | ||
'es-md' => [ | ||
'Fiesta de la Comunidad de Madrid' => '05-02', | ||
] + $juevesSanto + $santiagoApostol, | ||
|
||
// Ciudad Autónoma de Melilla | ||
'es-ml' => $juevesSanto + $fiestaSacrificio + $inmaculadaConcepcion, | ||
|
||
// Comunidad Foral de Navarra / Nafarroako Foru Komunitatea | ||
'es-nc' => $juevesSanto + $lunesPascua + $santiagoApostol, | ||
|
||
// País Vasco / Euskal Herria | ||
'es-pv' => $juevesSanto + $lunesPascua + $santiagoApostol, | ||
|
||
// La Rioja | ||
'es-ri' => [ | ||
'Lunes siguiente al Día de La Rioja' => '06-10', | ||
] + $juevesSanto + $lunesPascua, | ||
|
||
// Comunidad Valenciana / Comunitat Valenciana | ||
'es-vc' => [ | ||
'Día de la Comunidad Valenciana' => '10-09', | ||
] + $sanJose + $lunesPascua + $sanJuan, | ||
|
||
default => [], | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I think we should throw an exception, as we won't be returning the region based holidays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, and implement some direct way to also return national holidays, which are still valid, when there is no regional information for a specific year?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer an exception, as the user clearly expects region based holidays, which we cannot provide.
This can be a dedicated RuntimeException class, so it's easier to catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use InvalidYear::rang()