Finland   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 32
c 0
b 0
f 0
dl 0
loc 132
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 22 1
A calculateIndependenceDay() 0 8 2
A calculateAllSaintsDay() 0 7 1
A calculateStJohnsDay() 0 9 2
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;
14
15
use DateTime;
16
use Yasumi\Exception\InvalidDateException;
17
use Yasumi\Exception\UnknownLocaleException;
18
use Yasumi\Holiday;
19
20
/**
21
 * Provider for all holidays in Finland.
22
 */
23
class Finland extends AbstractProvider
24
{
25
    use CommonHolidays, ChristianHolidays;
26
27
    /**
28
     * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
29
     * country or sub-region.
30
     */
31
    public const ID = 'FI';
32
33
    /**
34
     * Initialize holidays for Finland.
35
     *
36
     * @throws InvalidDateException
37
     * @throws \InvalidArgumentException
38
     * @throws UnknownLocaleException
39
     * @throws \Exception
40
     */
41
    public function initialize(): void
42
    {
43
        $this->timezone = 'Europe/Helsinki';
44
45
        // Add common holidays
46
        $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
47
        $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
48
49
        // Add common Christian holidays (common in Finland)
50
        $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale));
51
        $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale));
52
        $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale));
53
        $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale));
54
        $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale));
55
        $this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale));
56
        $this->calculateStJohnsDay(); // aka Midsummer's Day
57
        $this->calculateAllSaintsDay();
58
        $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
59
        $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale));
60
61
        // Calculate other holidays
62
        $this->calculateIndependenceDay();
63
    }
64
65
    /**
66
     * St. John's Day / Midsummer.
67
     *
68
     * Midsummer, also known as St John's Day, is the period of time centred upon the summer solstice, and more
69
     * specifically the Northern European celebrations that accompany the actual solstice or take place on a day
70
     * between June 19 and June 25 and the preceding evening. The exact dates vary between different cultures.
71
     * The Christian Church designated June 24 as the feast day of the early Christian martyr St John the Baptist, and
72
     * the observance of St John's Day begins the evening before, known as St John's Eve.
73
     *
74
     * In Finland since 1955, the holiday has always been on a Saturday (between June 20 and June 26). Earlier it was
75
     * always on June 24. Many of the celebrations of midsummer take place on midsummer eve, when many workplaces are
76
     * closed and shops must close their doors at noon.
77
     *
78
     * @link https://en.wikipedia.org/wiki/Midsummer#Finland
79
     *
80
     * @throws InvalidDateException
81
     * @throws \InvalidArgumentException
82
     * @throws UnknownLocaleException
83
     * @throws \Exception
84
     */
85
    private function calculateStJohnsDay(): void
86
    {
87
        $stJohnsDay = $this->year < 1955 ? "$this->year-6-24" : "$this->year-6-20 this saturday";
88
89
        $this->addHoliday(new Holiday(
90
            'stJohnsDay',
91
            [],
92
            new DateTime($stJohnsDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)),
93
            $this->locale
94
        ));
95
    }
96
97
    /**
98
     * All Saints Day.
99
     *
100
     * All Saints' Day is a celebration of all Christian saints, particularly those who have no special feast days of
101
     * their own, in many Roman Catholic, Anglican and Protestant churches. In many western churches it is annually
102
     * held
103
     * November 1 and in many eastern churches it is celebrated on the first Sunday after Pentecost. It is also known
104
     * as All Hallows Tide, All-Hallomas, or All Hallows' Day.
105
     *
106
     * The festival was retained after the Reformation in the calendar of the Anglican Church and in many Lutheran
107
     * churches. In the Lutheran churches, such as the Church of Sweden, it assumes a role of general commemoration of
108
     * the dead. In the Swedish and Finnish calendar, the observance takes place on the Saturday between 31 October and
109
     * 6 November. In many Lutheran Churches, it is moved to the first Sunday of November.
110
     *
111
     * @link https://en.wikipedia.org/wiki/All_Saints%27_Day
112
     * @link https://fi.wikipedia.org/wiki/Pyh%C3%A4inp%C3%A4iv%C3%A4
113
     *
114
     * @throws InvalidDateException
115
     * @throws \InvalidArgumentException
116
     * @throws UnknownLocaleException
117
     * @throws \Exception
118
     */
119
    private function calculateAllSaintsDay(): void
120
    {
121
        $this->addHoliday(new Holiday(
122
            'allSaintsDay',
123
            [],
124
            new DateTime("$this->year-10-31 this saturday", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
125
            $this->locale
126
        ));
127
    }
128
129
    /**
130
     * Independence Day
131
     *
132
     * Finland's Independence Day (Finnish: itsenäisyyspäivä, Swedish: självständighetsdagen) is a national public
133
     * holiday, and a flag day, held on 6 December to celebrate Finland's declaration of independence from the Russian
134
     * Republic in 1917.
135
     *
136
     * Independence Day was first celebrated in 1917. However, during the first years of independence, 6 December in
137
     * some parts of Finland was only a minor holiday compared to 16 May, the Whites' day of celebration for prevailing
138
     * in the Finnish Civil War.
139
     *
140
     * @link https://en.wikipedia.org/wiki/Independence_Day_(Finland)
141
     *
142
     * @throws InvalidDateException
143
     * @throws \InvalidArgumentException
144
     * @throws UnknownLocaleException
145
     * @throws \Exception
146
     */
147
    private function calculateIndependenceDay(): void
148
    {
149
        if ($this->year >= 1917) {
150
            $this->addHoliday(new Holiday(
151
                'independenceDay',
152
                ['fi' => 'Itsenäisyyspäivä'],
153
                new DateTime("$this->year-12-6", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
154
                $this->locale
155
            ));
156
        }
157
    }
158
}
159