From 36f2574a1a21237865d487db8ef9e52d43a1a9d6 Mon Sep 17 00:00:00 2001 From: Tyler Shuster Date: Fri, 17 Jun 2022 17:18:49 -0700 Subject: [PATCH] Update Juneteenth with observed dates --- src/Yasumi/Provider/USA.php | 29 ++++++++++++++++++++++++++--- tests/USA/JuneteenthTest.php | 8 ++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Yasumi/Provider/USA.php b/src/Yasumi/Provider/USA.php index 3153f62be..26a61c106 100644 --- a/src/Yasumi/Provider/USA.php +++ b/src/Yasumi/Provider/USA.php @@ -161,9 +161,32 @@ private function calculateMemorialDay(): void private function calculateJuneteenth(): void { if ($this->year >= 2021) { - $this->addHoliday(new Holiday('juneteenth', [ - 'en' => 'Juneteenth', - ], new DateTime("$this->year-6-19", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale)); + $date = new DateTime("$this->year-6-19", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $label = 'Juneteenth'; + + $holiday = new Holiday('juneteenth', [ + 'en' => $label, + ], $date, $this->locale); + $this->addHoliday($holiday); + + $day_of_week = (int) $date->format('w'); + + if (0 === $day_of_week || 6 === $day_of_week) { + $date = clone $holiday; + if (0 === $day_of_week) { + $date->modify('next monday'); + } elseif (6 === $day_of_week) { + $date->modify('previous friday'); + } + $this->addHoliday(new SubstituteHoliday( + $holiday, + [ + 'en' => $label.' (observed)', + ], + $date, + $this->locale + )); + } } } diff --git a/tests/USA/JuneteenthTest.php b/tests/USA/JuneteenthTest.php index 7df2d81cd..9eddac00a 100644 --- a/tests/USA/JuneteenthTest.php +++ b/tests/USA/JuneteenthTest.php @@ -59,9 +59,9 @@ public function testJuneteenthOnAfter2021(): void public function testJuneteenthOnAfter2021SubstitutedMonday(): void { $year = 2022; - $this->assertHoliday( + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:juneteenth', + self::HOLIDAY, $year, new DateTime("$year-6-20", new DateTimeZone(self::TIMEZONE)) ); @@ -75,9 +75,9 @@ public function testJuneteenthOnAfter2021SubstitutedMonday(): void public function testJuneteenthOnAfter2021SubstitutedFriday(): void { $year = 2021; - $this->assertHoliday( + $this->assertSubstituteHoliday( self::REGION, - 'substituteHoliday:juneteenth', + self::HOLIDAY, $year, new DateTime("$year-6-18", new DateTimeZone(self::TIMEZONE)) );