forked from azuyalabs/yasumi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_provider.php
More file actions
56 lines (46 loc) · 1.7 KB
/
custom_provider.php
File metadata and controls
56 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types = 1);
/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2026 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/
// This file demonstrates the use of a custom Holiday provider. A custom holiday provider can be used for
// those scenarios where you would need only a subset of holidays of an existing provider. Or, if you like to
// extend an existing provider with additional, non-standard holidays.
require 'vendor/autoload.php';
/** Provider for all observed holidays by the NYSE (New York Stock Exchange) */
class NYSE extends Yasumi\Provider\USA
{
/**
* Initialize holidays for the NYSE.
*
* @throws Exception
*/
public function initialize(): void
{
parent::initialize();
// Add Good Friday
$this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale));
// Remove Columbus Day and Veterans Day
$this->removeHoliday('columbusDay');
$this->removeHoliday('veteransDay');
}
}
// Use the factory method to create a new holiday provider instance
$NYSEHolidays = Yasumi\Yasumi::create(NYSE::class, (int) date('Y'));
// We then can retrieve the NYSE observed holidays in the usual manner:
echo 'List of all the holiday names: ' . PHP_EOL;
foreach ($NYSEHolidays->getHolidayNames() as $day) {
echo $day . PHP_EOL;
}
echo PHP_EOL;
// Use the count() method to show how many holidays are returned
echo "Number of defined holidays: {$NYSEHolidays->count()}" . PHP_EOL;