From 5965006f7791e5a26f7c2e64839f08527bd54ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Schillinger?= Date: Tue, 22 Dec 2020 15:17:28 +0100 Subject: [PATCH] Add holidays for Spain --- README.md | 1 + src/Provider/ES.php | 127 +++++++++++++++++++++++++++++++++++++++ test/Provider/ESTest.php | 84 ++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 src/Provider/ES.php create mode 100644 test/Provider/ESTest.php diff --git a/README.md b/README.md index 3499462..c73ecc9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Checkdomain/Holiday is a small library to check if a specified date is a holiday - 🇩🇪 **DE** Germany - 🇩🇰 **DK** Denmark - 🇪🇪 **EE** Estonia +- 🇪🇸 **ES** Spain - 🇫🇷 **FR** France - 🇭🇺 **HU** Hungary - 🇮🇹 **IT** Italy diff --git a/src/Provider/ES.php b/src/Provider/ES.php new file mode 100644 index 0000000..eaeaf42 --- /dev/null +++ b/src/Provider/ES.php @@ -0,0 +1,127 @@ + + * @since 2020-12-22 + */ +class ES extends AbstractEaster +{ + const STATE_AN = 'Andalucía'; + const STATE_AR = 'Aragón'; + const STATE_CA = 'Cataluña'; + const STATE_CE = 'Ceuta'; + const STATE_CL = 'Castilla y León'; + const STATE_CM = 'Castilla La Mancha'; + const STATE_CN = 'Cantabria'; + const STATE_CV = 'Comunidad Valenciana'; + const STATE_EX = 'Extremadura'; + const STATE_GA = 'Galicia'; + const STATE_IB = 'Islas Baleares'; + const STATE_IC = 'Islas Canarias'; + const STATE_LR = 'La Rioja'; + const STATE_MA = 'Madrid'; + const STATE_ME = 'Melilla'; + const STATE_MU = 'Murcia'; + const STATE_PA = 'Principado de Asturias'; + const STATE_PV = 'País Vasco'; + + /** + * @param int $year + * + * @return mixed + */ + public function getHolidaysByYear($year) + { + $easter = $this->getEasterDates($year); + + $holidays = array( + '01-01' => $this->createData('Año Nuevo'), + '01-06' => $this->createData('Epifanía'), + '02-28' => $this->createData('Día de la comunidad', array( + self::STATE_AN, + )), + '03-01' => $this->createData('Día de la comunidad', array( + self::STATE_IB, + )), + '03-19' => $this->createData('San José', array( + self::STATE_CM, + self::STATE_CV, + self::STATE_GA, + self::STATE_IB, + self::STATE_MA, + self::STATE_ME, + self::STATE_MU, + self::STATE_PA, + )), + '04-23' => $this->createData('Día de la comunidad', array( + self::STATE_AR, + self::STATE_CA, + self::STATE_CL, + )), + '05-01' => $this->createData('Fiesta del Trabajo'), + '05-02' => $this->createData('Día de la comunidad', array( + self::STATE_MA, + )), + '05-30' => $this->createData('Día de la comunidad', array( + self::STATE_IC, + )), + '05-17' => $this->createData('Día das Letras Galegas', array( + self::STATE_GA, + )), + '05-31' => $this->createData('Día de la comunidad', array( + self::STATE_CM, + )), + '06-09' => $this->createData('Día de la comunidad', array( + self::STATE_LR, + self::STATE_MU, + )), + '07-25' => $this->createData('Santiago Apóstol', array( + self::STATE_GA, + self::STATE_MA, + )), + '08-15' => $this->createData('Asunción de la Virgen Maria'), + '09-02' => $this->createData('Día de la comunidad', array( + self::STATE_CE, + )), + '09-08' => $this->createData('Día de la comunidad', array( + self::STATE_EX, + self::STATE_PA, + )), + '09-11' => $this->createData('Día de la comunidad', array( + self::STATE_CA, + )), + '09-15' => $this->createData('Día de la comunidad', array( + self::STATE_CN, + )), + '10-09' => $this->createData('Día de la comunidad', array( + self::STATE_CV, + )), + '10-12' => $this->createData('Fiesta Nacional de España'), + '10-25' => $this->createData('Euskadi Eguna', array( + self::STATE_PV, + )), + '11-01' => $this->createData('Todos los Santos'), + '12-06' => $this->createData('Día de la Constitución'), + '12-08' => $this->createData('La Inmaculada Concepción'), + '12-25' => $this->createData('Navidad del Señor'), + '12-26' => $this->createData('San Esteban'), + // Variable dates + $easter['goodFriday']->format(self::DATE_FORMAT) => $this->createData('Viernes Santo'), + $easter['easterMonday']->format(self::DATE_FORMAT) => $this->createData('Lunes de Pascua', array( + self::STATE_CA, + self::STATE_CV, + self::STATE_IB, + self::STATE_PV, + )), + $easter['corpusChristi']->format(self::DATE_FORMAT) => $this->createData('Corpus Cristi', array( + self::STATE_MA, + )), + ); + + return $holidays; + } +} diff --git a/test/Provider/ESTest.php b/test/Provider/ESTest.php new file mode 100644 index 0000000..b2ad8e2 --- /dev/null +++ b/test/Provider/ESTest.php @@ -0,0 +1,84 @@ +provider = new ES(); + } + + /** + * Provides some test dates and the expectation + * + * @return array + */ + public function dateProvider() + { + return array( + array('2020-01-01', null, array('name' => 'Año Nuevo')), + array('2020-01-06', null, array('name' => 'Epifanía')), + array('2020-04-10', null, array('name' => 'Viernes Santo')), + array('2021-04-02', null, array('name' => 'Viernes Santo')), + array('2020-05-01', null, array('name' => 'Fiesta del Trabajo')), + array('2020-08-15', null, array('name' => 'Asunción de la Virgen Maria')), + array('2020-10-12', null, array('name' => 'Fiesta Nacional de España')), + array('2020-11-01', null, array('name' => 'Todos los Santos')), + array('2020-12-06', null, array('name' => 'Día de la Constitución')), + array('2020-12-08', null, array('name' => 'La Inmaculada Concepción')), + array('2020-12-25', null, array('name' => 'Navidad del Señor')), + array('2020-12-26', null, array('name' => 'San Esteban')), + + array('2020-02-28', ES::STATE_AN, array('name' => 'Día de la comunidad')), + array('2020-04-23', ES::STATE_AR, array('name' => 'Día de la comunidad')), + array('2020-04-23', ES::STATE_CA, array('name' => 'Día de la comunidad')), + array('2020-04-23', ES::STATE_CL, array('name' => 'Día de la comunidad')), + array('2020-03-01', ES::STATE_IB, array('name' => 'Día de la comunidad')), + array('2020-05-02', ES::STATE_MA, array('name' => 'Día de la comunidad')), + array('2020-05-30', ES::STATE_IC, array('name' => 'Día de la comunidad')), + array('2020-05-31', ES::STATE_CM, array('name' => 'Día de la comunidad')), + array('2020-06-09', ES::STATE_LR, array('name' => 'Día de la comunidad')), + array('2020-06-09', ES::STATE_MU, array('name' => 'Día de la comunidad')), + array('2020-09-02', ES::STATE_CE, array('name' => 'Día de la comunidad')), + array('2020-09-08', ES::STATE_EX, array('name' => 'Día de la comunidad')), + array('2020-09-08', ES::STATE_PA, array('name' => 'Día de la comunidad')), + array('2020-09-11', ES::STATE_CA, array('name' => 'Día de la comunidad')), + array('2020-09-15', ES::STATE_CN, array('name' => 'Día de la comunidad')), + array('2020-10-09', ES::STATE_CV, array('name' => 'Día de la comunidad')), + + array('2020-03-19', ES::STATE_CM, array('name' => 'San José')), + array('2020-03-19', ES::STATE_CV, array('name' => 'San José')), + array('2020-03-19', ES::STATE_GA, array('name' => 'San José')), + array('2020-03-19', ES::STATE_IB, array('name' => 'San José')), + array('2020-03-19', ES::STATE_MA, array('name' => 'San José')), + array('2020-03-19', ES::STATE_ME, array('name' => 'San José')), + array('2020-03-19', ES::STATE_MU, array('name' => 'San José')), + array('2020-03-19', ES::STATE_PA, array('name' => 'San José')), + + array('2020-05-17', ES::STATE_GA, array('name' => 'Día das Letras Galegas')), + + array('2020-07-25', ES::STATE_GA, array('name' => 'Santiago Apóstol')), + array('2020-07-25', ES::STATE_MA, array('name' => 'Santiago Apóstol')), + + array('2020-10-25', ES::STATE_PV, array('name' => 'Euskadi Eguna')), + + array('2021-04-05', ES::STATE_CA, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_CV, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_IB, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_PV, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_CA, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_CV, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_IB, array('name' => 'Lunes de Pascua')), + array('2021-04-05', ES::STATE_PV, array('name' => 'Lunes de Pascua')), + + array('2020-06-11', ES::STATE_MA, array('name' => 'Corpus Cristi')), + ); + } +}