Fix "Pentecôte" and mother day

master
Julien Rosset 2 years ago
parent 2f65a54adb
commit ae115578ce

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

Loading…
Cancel
Save