|
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 Quebec (Canada). |
|
24
|
|
|
* |
|
25
|
|
|
* Quebec is a province of Canada. |
|
26
|
|
|
* |
|
27
|
|
|
* @link https://en.wikipedia.org/wiki/Quebec |
|
28
|
|
|
*/ |
|
29
|
|
|
class Quebec 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-QC'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Initialize holidays for Quebec (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/Toronto'; |
|
50
|
|
|
|
|
51
|
|
|
$this->addHoliday($this->saintJeanBaptisteDay($this->year, $this->timezone, $this->locale)); |
|
52
|
|
|
$this->calculateNationalPatriotsDay(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Saint-Jean-Baptiste Day. |
|
57
|
|
|
* |
|
58
|
|
|
* The Nativity of John the Baptist (or Birth of John the Baptist, or Nativity of the Forerunner) is a Christian |
|
59
|
|
|
* feast day celebrating the birth of John the Baptist, a prophet who foretold the coming of the Messiah in the |
|
60
|
|
|
* person of Jesus, whom he later baptised. The Nativity of John the Baptist on June 24 comes three months after the |
|
61
|
|
|
* celebration on March 25 of the Annunciation, when the angel Gabriel told Mary that her cousin Elizabeth was in |
|
62
|
|
|
* her sixth month of pregnancy. |
|
63
|
|
|
* |
|
64
|
|
|
* @link https://en.wikipedia.org/wiki/Saint-Jean-Baptiste_Day |
|
65
|
|
|
* |
|
66
|
|
|
* @param int $year the year for which St. John's Day need to be created |
|
67
|
|
|
* @param string $timezone the timezone in which St. John's Day is celebrated |
|
68
|
|
|
* @param string $locale the locale for which St. John's Day need to be displayed in. |
|
69
|
|
|
* @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, |
|
70
|
|
|
* TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. |
|
71
|
|
|
* |
|
72
|
|
|
* @return Holiday |
|
73
|
|
|
* |
|
74
|
|
|
* @throws InvalidDateException |
|
75
|
|
|
* @throws UnknownLocaleException |
|
76
|
|
|
* @throws \InvalidArgumentException |
|
77
|
|
|
* @throws \Exception |
|
78
|
|
|
*/ |
|
79
|
|
|
public function saintJeanBaptisteDay( |
|
80
|
|
|
int $year, |
|
81
|
|
|
string $timezone, |
|
82
|
|
|
string $locale, |
|
83
|
|
|
string $type = Holiday::TYPE_OFFICIAL |
|
84
|
|
|
): Holiday { |
|
85
|
|
|
return new Holiday( |
|
86
|
|
|
'saintJeanBaptisteDay', |
|
87
|
|
|
[], |
|
88
|
|
|
new DateTime("$year-06-24", DateTimeZoneFactory::getDateTimeZone($timezone)), |
|
89
|
|
|
$locale, |
|
90
|
|
|
$type |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* National Patriot's Day. |
|
96
|
|
|
* |
|
97
|
|
|
* @link https://en.wikipedia.org/wiki/National_Patriots%27_Day |
|
98
|
|
|
* |
|
99
|
|
|
* @throws InvalidDateException |
|
100
|
|
|
* @throws \InvalidArgumentException |
|
101
|
|
|
* @throws UnknownLocaleException |
|
102
|
|
|
* @throws \Exception |
|
103
|
|
|
*/ |
|
104
|
|
|
private function calculateNationalPatriotsDay(): void |
|
105
|
|
|
{ |
|
106
|
|
|
if ($this->year < 2003) { |
|
107
|
|
|
return; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$this->addHoliday(new Holiday( |
|
111
|
|
|
'nationalPatriotsDay', |
|
112
|
|
|
[], |
|
113
|
|
|
new DateTime("last monday front of $this->year-05-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), |
|
114
|
|
|
$this->locale |
|
115
|
|
|
)); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|