diff --git a/php/PublicHolidayCalendar.php b/php/PublicHolidayCalendar.php index c1adcfb..a69ba44 100644 --- a/php/PublicHolidayCalendar.php +++ b/php/PublicHolidayCalendar.php @@ -164,11 +164,10 @@ class PublicHolidayCalendar { * @return Event[] The list of events */ private function createVariablePublicHolidays (int $year): array { - $paquesDate = static::calculatePaques($year); return [ - static::createEvent('Pâques', 'Lundi de Pâques', true, $paquesDate), - static::createEvent('Ascension', 'Jeudi de l\'Ascension', true, $paquesDate->add(new DateInterval('P39D'))), - static::createEvent('Pentecôte', 'Lundi de Pentecôte', true, $paquesDate->add(new DateInterval('P50D'))), + static::createEvent('Pâques', 'Lundi de Pâques', true, static::calculatePaques($year)), + static::createEvent('Ascension', 'Jeudi de l\'Ascension', true, static::calculateAscension($year)), + static::createEvent('Pentecôte', 'Pentecôte', true, static::calculatePentecote($year)), ]; } /** @@ -224,7 +223,7 @@ class PublicHolidayCalendar { * * @param int $year The year * - * @return DateTimeImmutable The of "Pâques" + * @return DateTimeImmutable The date of "Pâques" */ private static function calculatePaques (int $year): DateTimeImmutable { //https://fr.wikipedia.org/wiki/Calcul_de_la_date_de_P%C3%A2ques @@ -244,6 +243,27 @@ class PublicHolidayCalendar { return static::createDate($year, intdiv($paquesNumber, 31), ($paquesNumber % 31) + 1); } + /** + * Calculate the date of "Ascension" + * + * @param int $year The year + * + * @return DateTimeImmutable The date of "Ascension" + */ + private static function calculateAscension (int $year): DateTimeImmutable { + return self::calculatePaques($year)->add(new DateInterval('P39D')); + } + /** + * Calculate the date of "Pentecôte" + * + * @param int $year The year + * + * @return DateTimeImmutable The date of "Pentecôte" + */ + private static function calculatePentecote (int $year): DateTimeImmutable { + return self::calculatePaques($year)->add(new DateInterval('P49D')); + } + /** * Calculate the mother day * @@ -252,8 +272,6 @@ class PublicHolidayCalendar { * @return DateTimeImmutable The date */ private static function calculateMotherDay (int $year): DateTimeImmutable { - $paquesDate = static::calculatePaques($year); - $motherDay = static::createDate($year, 5, 31); $motherDayOfWeek = (int)$motherDay->format('N'); if ($motherDayOfWeek < 7) { @@ -263,7 +281,7 @@ class PublicHolidayCalendar { catch (Exception) { } } - if ($motherDay === $paquesDate) { + if ($motherDay === static::calculatePentecote($year)) { $motherDay = $motherDay->add(new DateInterval('P7D')); }