Yukon::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Yasumi package.
4
 *
5
 * Copyright (c) 2015 - 2020 AzuyaLabs
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Sacha Telgenhof <[email protected]>
11
 */
12
13
namespace Yasumi\Provider\Canada;
14
15
use DateTime;
16
use Yasumi\Exception\InvalidDateException;
17
use Yasumi\Exception\UnknownLocaleException;
18
use Yasumi\Holiday;
19
use Yasumi\Provider\Canada;
20
use Yasumi\Provider\DateTimeZoneFactory;
21
22
/**
23
 * Provider for all holidays in Yukon (Canada).
24
 *
25
 * Manitoba is a territory of Canada.
26
 *
27
 * @link https://en.wikipedia.org/wiki/Yukon
28
 */
29
class Yukon extends Canada
30
{
31
    /**
32
     * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
33
     * country or sub-region.
34
     */
35
    public const ID = 'CA-YT';
36
37
    /**
38
     * Initialize holidays for Yukon (Canada).
39
     *
40
     * @throws InvalidDateException
41
     * @throws \InvalidArgumentException
42
     * @throws UnknownLocaleException
43
     * @throws \Exception
44
     */
45
    public function initialize(): void
46
    {
47
        parent::initialize();
48
        
49
        $this->timezone = 'America/Whitehorse';
50
        
51
        $this->calculateDiscoveryDay();
52
        $this->calculateHeritageDay();
53
        $this->calculateNationalIndigenousPeoplesDay();
54
        $this->calculateVictoriaDay();
55
    }
56
57
    /**
58
     * Discovery Day.
59
     *
60
     * @link https://en.wikipedia.org/wiki/Civic_Holiday
61
     *
62
     * @throws InvalidDateException
63
     * @throws \InvalidArgumentException
64
     * @throws UnknownLocaleException
65
     * @throws \Exception
66
     */
67
    protected function calculateDiscoveryDay(): void
68
    {
69
        if ($this->year < 1897) {
70
            return;
71
        }
72
73
        $this->addHoliday(new Holiday(
74
            'discoveryDay',
75
            [],
76
            new DateTime("third monday of august $this->year", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
77
            $this->locale
78
        ));
79
    }
80
81
    /**
82
     * Yukon Heritage Day.
83
     *
84
     * @link https://en.wikipedia.org/wiki/Family_Day_(Canada)
85
     *
86
     * @throws InvalidDateException
87
     * @throws \InvalidArgumentException
88
     * @throws UnknownLocaleException
89
     * @throws \Exception
90
     */
91
    protected function calculateHeritageDay(): void
92
    {
93
        if ($this->year < 2009) {
94
            return;
95
        }
96
97
        $this->addHoliday(new Holiday(
98
            'yukonHeritageDay',
99
            [],
100
            new DateTime("first monday of august $this->year", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
101
            $this->locale
102
        ));
103
    }
104
}
105