Estonia::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 17
rs 9.8333
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Yasumi package.
5
 *
6
 * Copyright (c) 2015 - 2020 AzuyaLabs
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author Sacha Telgenhof <[email protected]>
12
 */
13
14
namespace Yasumi\Provider;
15
16
use Yasumi\Holiday;
17
18
/**
19
 * Provider for all holidays in Estonia.
20
 *
21
 * @author Gedas Lukošius <[email protected]>
22
 */
23
class Estonia extends AbstractProvider
24
{
25
    use CommonHolidays, ChristianHolidays;
26
27
    public const DECLARATION_OF_INDEPENDENCE_YEAR = 1918;
28
29
    public const VICTORY_DAY_START_YEAR = 1934;
30
31
    public const RESTORATION_OF_INDEPENDENCE_YEAR = 1991;
32
33
    /**
34
     * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
35
     * country or sub-region.
36
     */
37
    public const ID = 'EE';
38
39
    /**
40
     * Initialize holidays for Estonia.
41
     *
42
     * @throws \InvalidArgumentException
43
     * @throws \Exception
44
     */
45
    public function initialize(): void
46
    {
47
        $this->timezone = 'Europe/Tallinn';
48
49
        // Official
50
        $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
51
        $this->addIndependenceDay();
52
        $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale));
53
        $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale));
54
        $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
55
        $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale));
56
        $this->addVictoryDay();
57
        $this->addHoliday($this->stJohnsDay($this->year, $this->timezone, $this->locale));
58
        $this->addRestorationOfIndependenceDay();
59
        $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL));
60
        $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
61
        $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale));
62
    }
63
64
    /**
65
     * @throws \InvalidArgumentException
66
     * @throws \Exception
67
     */
68
    private function addIndependenceDay(): void
69
    {
70
        if ($this->year >= self::DECLARATION_OF_INDEPENDENCE_YEAR) {
71
            $this->addHoliday(new Holiday('independenceDay', [
72
                'en' => 'Independence Day',
73
                'et' => 'Iseseisvuspäev',
74
            ], new \DateTime("{$this->year}-02-24", new \DateTimeZone($this->timezone))));
75
        }
76
    }
77
78
    /**
79
     * @throws \InvalidArgumentException
80
     * @throws \Exception
81
     */
82
    private function addVictoryDay(): void
83
    {
84
        if ($this->year >= self::VICTORY_DAY_START_YEAR) {
85
            $this->addHoliday(new Holiday('victoryDay', [
86
                'en' => 'Victory Day',
87
                'et' => 'Võidupüha',
88
            ], new \DateTime("{$this->year}-06-23", new \DateTimeZone($this->timezone))));
89
        }
90
    }
91
92
    /**
93
     * @throws \InvalidArgumentException
94
     * @throws \Exception
95
     */
96
    private function addRestorationOfIndependenceDay(): void
97
    {
98
        if ($this->year >= self::RESTORATION_OF_INDEPENDENCE_YEAR) {
99
            $this->addHoliday(new Holiday('restorationOfIndependenceDay', [
100
                'en' => 'Day of Restoration of Independence',
101
                'et' => 'Tasiseseisvumispäev',
102
            ], new \DateTime("{$this->year}-08-20", new \DateTimeZone($this->timezone))));
103
        }
104
    }
105
}
106