Skip to content

Commit 2713e27

Browse files
author
Art Kurbakov
committed
Added NYSETest.php
1 parent 30b7e34 commit 2713e27

2 files changed

Lines changed: 138 additions & 22 deletions

File tree

src/Yasumi/Provider/USA/NYSE.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
// weather, national emergencies and presidential proclamations.
2121
// All closure events are included from year 2000.
2222

23-
require 'vendor/autoload.php';
23+
namespace Yasumi\Provider\USA;
2424

25-
class NYSE extends Yasumi\Provider\USA
25+
use Yasumi\Provider\USA;
26+
use Yasumi\Holiday;
27+
use DateTime;
28+
29+
class NYSE extends USA
2630
{
2731
/**
2832
* Initialize holidays for the NYSE.
@@ -31,18 +35,23 @@ class NYSE extends Yasumi\Provider\USA
3135
*/
3236
public function initialize(): void
3337
{
34-
parent::initialize();
38+
$this->timezone = 'America/New_York';
3539

3640
// Add exhange-specific holidays
41+
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
42+
$this->calculateMartinLutherKingday();
43+
$this->calculateWashingtonsBirthday();
3744
$this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale));
38-
39-
// Remove exchange-specific holidays
40-
$this->removeHoliday('columbusDay');
41-
$this->removeHoliday('veteransDay');
42-
$this->holidaysCalculator->removeHoliday('substituteHoliday:veteransDay');
43-
if (2022 < $this->year)
44-
$this->removeHoliday('juneteenth');
45+
$this->calculateMemorialDay();
46+
if (2021 < $this->year)
47+
$this->calculateJuneteenth();
48+
$this->calculateIndependenceDay();
49+
$this->calculateLabourDay();
50+
$this->calculateThanksgivingDay();
51+
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
4552

53+
$this->calculateSubstituteHolidays();
54+
4655
// Add other full-day closure events
4756
$this->addWeatherEvents();
4857
$this->addEmergencies();
@@ -52,31 +61,31 @@ public function initialize(): void
5261
private function addWeatherEvents()
5362
{
5463
if (2012 == $this->year) {
55-
$this->holidaysCalculator->addHoliday(new Holiday('HurricaneSandy1', [], new DateTime('2012-10-29')));
56-
$this->holidaysCalculator->addHoliday(new Holiday('HurricaneSandy2', [], new DateTime('2012-10-30')));
64+
$this->addHoliday(new Holiday('hurricaneSandy1', [], new DateTime('2012-10-29')));
65+
$this->addHoliday(new Holiday('hurricaneSandy2', [], new DateTime('2012-10-30')));
5766
}
5867
}
5968

6069
private function addEmergencies()
6170
{
6271
if (2001 == $this->year) {
63-
$this->holidaysCalculator->addHoliday(new Holiday('WTCAttack1', [], new DateTime('2001-09-11')));
64-
$this->holidaysCalculator->addHoliday(new Holiday('WTCAttack2', [], new DateTime('2001-09-12')));
65-
$this->holidaysCalculator->addHoliday(new Holiday('WTCAttack3', [], new DateTime('2001-09-13')));
66-
$this->holidaysCalculator->addHoliday(new Holiday('WTCAttack4', [], new DateTime('2001-09-14')));
72+
$this->addHoliday(new Holiday('WTCAttack1', [], new DateTime('2001-09-11')));
73+
$this->addHoliday(new Holiday('WTCAttack2', [], new DateTime('2001-09-12')));
74+
$this->addHoliday(new Holiday('WTCAttack3', [], new DateTime('2001-09-13')));
75+
$this->addHoliday(new Holiday('WTCAttack4', [], new DateTime('2001-09-14')));
6776
}
6877
}
6978

7079
private function addProclamations()
7180
{
7281
if (2004 == $this->year)
73-
$this->holidaysCalculator->addHoliday(new Holiday('ReaganMourning', [], new DateTime('2004-06-11')));
82+
$this->addHoliday(new Holiday('ReaganMourning', [], new DateTime('2004-06-11')));
7483
if (2007 == $this->year)
75-
$this->holidaysCalculator->addHoliday(new Holiday('GRFordMourning', [], new DateTime('2007-01-02')));
84+
$this->addHoliday(new Holiday('GRFordMourning', [], new DateTime('2007-01-02')));
7685
if (2018 == $this->year)
77-
$this->holidaysCalculator->addHoliday(new Holiday('HWBushMourning', [], new DateTime('2018-12-05')));
86+
$this->addHoliday(new Holiday('HWBushMourning', [], new DateTime('2018-12-05')));
7887
if (2025 == $this->year)
79-
$this->holidaysCalculator->addHoliday(new Holiday('CarterMourning', [], new DateTime('2025-01-09')));
88+
$this->addHoliday(new Holiday('CarterMourning', [], new DateTime('2025-01-09')));
8089
}
8190

8291
public function getSources(): array
@@ -89,7 +98,5 @@ public function getSources(): array
8998
'https://www.thecorporatecounsel.net/blog/2021/10/nyse-makes-juneteenth-a-new-market-holiday.html',
9099
];
91100
}
92-
93-
94101
}
95102

tests/USA/NYSE/NYSETest.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
/**
6+
* This file is part of the 'Yasumi' package.
7+
*
8+
* The easy PHP Library for calculating holidays.
9+
*
10+
* Copyright (c) 2025 Magic Web Group
11+
*
12+
* For the full copyright and license information, please view the LICENSE
13+
* file that was distributed with this source code.
14+
*
15+
* @author Art Kurbakov <admin at mgwebgroup dot com>
16+
*/
17+
18+
namespace Yasumi\tests\USA\NYSE;
19+
20+
use Yasumi\Holiday;
21+
use Yasumi\tests\ProviderTestCase;
22+
use Yasumi\tests\USA\USABaseTestCase;
23+
24+
/**
25+
* Class for testing closure days for NYSE
26+
*/
27+
class NYSETest extends USABaseTestCase implements ProviderTestCase
28+
{
29+
/**
30+
* Country (name) to be tested.
31+
*/
32+
public const REGION = 'USA/NYSE';
33+
34+
/**
35+
* @var int year random year number used for all tests in this Test Case
36+
*/
37+
protected int $year;
38+
39+
/**
40+
* Initial setup of this Test Case.
41+
*
42+
* @throws \Exception
43+
*/
44+
protected function setUp(): void
45+
{
46+
$this->year = $this->generateRandomYear(2000);
47+
}
48+
49+
/**
50+
* Tests if all official holidays in the USA are defined by the provider class.
51+
*/
52+
public function testOfficialHolidays(): void
53+
{
54+
$holidays = [
55+
'newYearsDay',
56+
'martinLutherKingDay',
57+
'washingtonsBirthday',
58+
'goodFriday',
59+
'memorialDay',
60+
'independenceDay',
61+
'labourDay',
62+
'thanksgivingDay',
63+
'christmasDay',
64+
];
65+
66+
if (2001 == $this->year) {
67+
$holidays[] = 'WTCAttack1';
68+
$holidays[] = 'WTCAttack2';
69+
$holidays[] = 'WTCAttack3';
70+
$holidays[] = 'WTCAttack4';
71+
}
72+
73+
if (2004 == $this->year) {
74+
$holidays[] = 'ReaganMourning';
75+
}
76+
77+
if (2007 == $this->year) {
78+
$holidays[] = 'GRFordMourning';
79+
}
80+
81+
if (2012 == $this->year) {
82+
$holidays[] = 'hurricaneSandy1';
83+
$holidays[] = 'hurricaneSandy2';
84+
}
85+
86+
if (2018 == $this->year) {
87+
$holidays[] = 'HWBushMourning';
88+
}
89+
90+
if (2021 > $this->year) {
91+
$holidays[] = 'juneteenth';
92+
}
93+
94+
if (2025 > $this->year) {
95+
$holidays[] = 'CarterMourning';
96+
}
97+
98+
$this->assertDefinedHolidays($holidays, self::REGION, $this->year, Holiday::TYPE_OFFICIAL);
99+
}
100+
101+
/**
102+
* @throws \ReflectionException
103+
* @throws \Exception
104+
*/
105+
public function testSources(): void
106+
{
107+
$this->assertSources(self::REGION, 5);
108+
}
109+
}

0 commit comments

Comments
 (0)