Skip to content

Commit

Permalink
Add new US federal holiday Juneteenth National Independence Day.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheintz committed Jun 25, 2021
1 parent e8e643e commit 67a27c0
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Yasumi/Provider/USA.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function initialize(): void
$this->calculateMartinLutherKingday();
$this->calculateWashingtonsBirthday();
$this->calculateMemorialDay();
$this->calculateJuneteenth();
$this->calculateIndependenceDay();
$this->calculateLabourDay();
$this->calculateColumbusDay();
Expand Down Expand Up @@ -138,6 +139,27 @@ private function calculateMemorialDay(): void
}
}

/**
* Juneteenth National Independence Day.
*
* Juneteenth National Independence Day, commonly known simply as Juneteenth, is a federal holiday in the United
* States commemorating the end of slavery. Established as a federal holiday on June 17, 2021, Juneteenth is
* celebrated annually on June 19. In case Juneteenth falls on a Sunday, a substituted holiday is observed
* the following Monday. If it falls on a Saturday, a substituted holiday is observed the previous Friday.
*
* @see https://en.wikipedia.org/wiki/Juneteenth
*
* @throws \Exception
*/
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));
}
}

/**
* Independence Day.
*
Expand Down
133 changes: 133 additions & 0 deletions tests/USA/JuneteenthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

declare(strict_types=1);
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2021 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/

namespace Yasumi\tests\USA;

use DateTime;
use DateTimeZone;
use Exception;
use ReflectionException;
use Yasumi\Holiday;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class to test Juneteenth.
*/
class JuneteenthTest extends USABaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday.
*/
public const HOLIDAY = 'juneteenth';

/**
* The year in which the holiday was first established.
*/
public const ESTABLISHMENT_YEAR = 2021;

/**
* Tests Juneteenth on or after 2021. Juneteenth is celebrated since 2021 on June 19th.
*
* @throws Exception
* @throws ReflectionException
*/
public function testJuneteenthOnAfter2021(): void
{
$year = 2023;
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new DateTime("$year-6-19", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests Juneteenth on or after 2021 when substituted on Monday (when Juneteenth falls on Sunday).
*
* @throws Exception
* @throws ReflectionException
*/
public function testJuneteenthOnAfter2021SubstitutedMonday(): void
{
$year = 2022;
$this->assertHoliday(
self::REGION,
'substituteHoliday:juneteenth',
$year,
new DateTime("$year-6-20", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests Juneteenth on or after 2021 when substituted on Friday (when Juneteenth falls on Saturday).
*
* @throws Exception
* @throws ReflectionException
*/
public function testJuneteenthOnAfter2021SubstitutedFriday(): void
{
$year = 2021;
$this->assertHoliday(
self::REGION,
'substituteHoliday:juneteenth',
$year,
new DateTime("$year-6-18", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests Juneteenth before 2021. Juneteenth is celebrated since 2021 on June 19th.
*
* @throws ReflectionException
*/
public function testJuneteenthBefore2021(): void
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1)
);
}

/**
* Tests translated name of the holiday defined in this test.
*
* @throws ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
[self::LOCALE => 'Juneteenth']
);
}

/**
* Tests type of the holiday defined in this test.
*
* @throws ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
Holiday::TYPE_OFFICIAL
);
}
}
1 change: 1 addition & 0 deletions tests/USA/USATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testOfficialHolidays(): void
'martinLutherKingDay',
'washingtonsBirthday',
'memorialDay',
'juneteenth',
'independenceDay',
'labourDay',
'columbusDay',
Expand Down

0 comments on commit 67a27c0

Please sign in to comment.