Skip to content
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

Update Juneteenth with observed dates #282

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/Yasumi/Provider/USA.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/USA/JuneteenthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
Expand All @@ -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))
);
Expand Down