Skip to content

Commit a757a7c

Browse files
authored
Improve Swiss providers (#233)
Improve Swiss providers with links to official laws.
1 parent e2f37e6 commit a757a7c

23 files changed

+853
-24
lines changed

src/Yasumi/Provider/Switzerland/Bern.php

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Provider for all holidays in Bern (Switzerland).
2323
*
2424
* @link https://en.wikipedia.org/wiki/Canton_of_Bern
25+
* @link https://www.fin.be.ch/fin/fr/index/personal/personalrecht/wdb.thema.212.html
2526
*/
2627
class Bern extends Switzerland
2728
{

src/Yasumi/Provider/Switzerland/Fribourg.php

+36
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212

1313
namespace Yasumi\Provider\Switzerland;
1414

15+
use DateTime;
1516
use Yasumi\Exception\InvalidDateException;
1617
use Yasumi\Exception\UnknownLocaleException;
1718
use Yasumi\Holiday;
1819
use Yasumi\Provider\ChristianHolidays;
20+
use Yasumi\Provider\DateTimeZoneFactory;
1921
use Yasumi\Provider\Switzerland;
2022

2123
/**
2224
* Provider for all holidays in Fribourg (Switzerland).
2325
*
2426
* @link https://en.wikipedia.org/wiki/Canton_of_Fribourg
27+
* @link https://www.fr.ch/travail-et-entreprises/employes/jour-ferie-jour-chome-quelle-difference
2528
*/
2629
class Fribourg extends Switzerland
2730
{
@@ -45,11 +48,44 @@ public function initialize(): void
4548
{
4649
parent::initialize();
4750

51+
// For the whole canton
4852
$this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
4953
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
5054
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
5155
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
56+
57+
// For the roman catholic communes
58+
$this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
59+
$this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
60+
$this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
61+
$this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
62+
63+
// For the reformed evangelical communes
5264
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
5365
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
66+
$this->calculateBerchtoldsTag($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
67+
$this->calculateDecember26th($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
68+
}
69+
70+
/**
71+
* December 26th
72+
*
73+
* @throws InvalidDateException
74+
* @throws \InvalidArgumentException
75+
* @throws UnknownLocaleException
76+
* @throws \Exception
77+
*/
78+
private function calculateDecember26th(): void
79+
{
80+
$this->addHoliday(new Holiday(
81+
'december26th',
82+
[
83+
'en' => 'December 26th',
84+
'fr' => '26 décembre',
85+
],
86+
new DateTime($this->year . '-12-26', DateTimeZoneFactory::getDateTimeZone($this->timezone)),
87+
$this->locale,
88+
Holiday::TYPE_OTHER
89+
));
5490
}
5591
}

src/Yasumi/Provider/Switzerland/Geneva.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Provider for all holidays in Geneva (Switzerland).
2626
*
2727
* @link https://en.wikipedia.org/wiki/Canton_of_Geneva
28+
* @link https://www.ge.ch/legislation/rsg/f/s/rsg_j1_45.html
2829
*/
2930
class Geneva extends Switzerland
3031
{

src/Yasumi/Provider/Switzerland/Jura.php

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Provider for all holidays in Jura (Switzerland).
2525
*
2626
* @link https://en.wikipedia.org/wiki/Canton_of_Jura
27+
* @link https://rsju.jura.ch/fr/viewdocument.html?idn=20105&id=26766
2728
*/
2829
class Jura extends Switzerland
2930
{
@@ -60,11 +61,14 @@ public function initialize(): void
6061
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6162
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6263
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
64+
$this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6365
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
66+
$this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6467
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6568

6669
$this->calculateBerchtoldsTag();
6770
$this->calculatePlebisciteJurassien();
71+
$this->calculateBettagsMontag();
6872
}
6973

7074
/**

src/Yasumi/Provider/Switzerland/Neuchatel.php

+60-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* Provider for all holidays in Neuchâtel (Switzerland).
2525
*
2626
* @link https://en.wikipedia.org/wiki/Canton_of_Neuch%C3%A2tel
27+
* @link http://rsn.ne.ch/DATA/program/books/RSN2017/20171/htm/94102.htm
28+
* @link https://www.ne.ch/themes/travail/Pages/jours-feries.aspx
2729
*/
2830
class Neuchatel extends Switzerland
2931
{
@@ -54,15 +56,26 @@ public function initialize(): void
5456
$this->locale,
5557
Holiday::TYPE_OTHER
5658
));
57-
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
58-
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
5959
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6060
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6161
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6262

63-
$this->calculateBerchtoldsTag();
6463
$this->calculateBettagsMontag();
6564
$this->calculateInstaurationRepublique();
65+
66+
$newYearsDay = $this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
67+
$this->addHoliday($newYearsDay);
68+
if ($newYearsDay->format('N') === '7') {
69+
// If the New Year's Day is a sunday, the next day is an holiday
70+
$this->calculateJanuary2nd();
71+
}
72+
73+
$christmasDay = $this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
74+
$this->addHoliday($christmasDay);
75+
if ($christmasDay->format('N') === '7') {
76+
// If the Christmas Day is a sunday, the next day is an holiday
77+
$this->calculateDecember26th();
78+
}
6679
}
6780

6881
/**
@@ -89,4 +102,48 @@ private function calculateInstaurationRepublique(): void
89102
));
90103
}
91104
}
105+
106+
/**
107+
* January 2nd
108+
*
109+
* @throws InvalidDateException
110+
* @throws \InvalidArgumentException
111+
* @throws UnknownLocaleException
112+
* @throws \Exception
113+
*/
114+
private function calculateJanuary2nd(): void
115+
{
116+
$this->addHoliday(new Holiday(
117+
'january2nd',
118+
[
119+
'en' => 'January 2nd',
120+
'fr' => '2 janvier',
121+
],
122+
new DateTime($this->year . '-01-02', DateTimeZoneFactory::getDateTimeZone($this->timezone)),
123+
$this->locale,
124+
Holiday::TYPE_OTHER
125+
));
126+
}
127+
128+
/**
129+
* December 26th
130+
*
131+
* @throws InvalidDateException
132+
* @throws \InvalidArgumentException
133+
* @throws UnknownLocaleException
134+
* @throws \Exception
135+
*/
136+
private function calculateDecember26th(): void
137+
{
138+
$this->addHoliday(new Holiday(
139+
'december26th',
140+
[
141+
'en' => 'December 26th',
142+
'fr' => '26 décembre',
143+
],
144+
new DateTime($this->year . '-12-26', DateTimeZoneFactory::getDateTimeZone($this->timezone)),
145+
$this->locale,
146+
Holiday::TYPE_OTHER
147+
));
148+
}
92149
}

src/Yasumi/Provider/Switzerland/Valais.php

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Provider for all holidays in Valais (Switzerland).
2323
*
2424
* @link https://en.wikipedia.org/wiki/Valais
25+
* @link https://www.vs.ch/web/spt/jours-feries
2526
*/
2627
class Valais extends Switzerland
2728
{

src/Yasumi/Provider/Switzerland/Vaud.php

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Provider for all holidays in Vaud (Switzerland).
2323
*
2424
* @link https://en.wikipedia.org/wiki/Vaud
25+
* @link https://www.vd.ch/themes/formation/jours-feries-et-vacances-scolaires/
2526
*/
2627
class Vaud extends Switzerland
2728
{

src/Yasumi/Provider/Switzerland/Zurich.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Provider for all holidays in Zürich (Switzerland).
2323
*
2424
* @link https://en.wikipedia.org/wiki/Canton_of_Z%C3%BCrich
25+
* @link https://www.zh.ch/de/wirtschaft-arbeit/arbeitsbedingungen/arbeitsssicherheit-gesundheitsschutz/arbeits-ruhezeiten/feiertage.html
2526
*/
2627
class Zurich extends Switzerland
2728
{
@@ -58,7 +59,5 @@ public function initialize(): void
5859
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
5960
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
6061
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
61-
62-
$this->calculateBerchtoldsTag();
6362
}
6463
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\tests\Switzerland\Fribourg;
14+
15+
use DateTime;
16+
use Exception;
17+
use ReflectionException;
18+
use Yasumi\Holiday;
19+
use Yasumi\tests\YasumiTestCaseInterface;
20+
21+
/**
22+
* Class for testing All Saints' Day in Fribourg (Switzerland).
23+
*/
24+
class AllSaintsDayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface
25+
{
26+
/**
27+
* The name of the holiday
28+
*/
29+
public const HOLIDAY = 'allSaintsDay';
30+
31+
/**
32+
* Tests All Saints' Day.
33+
*
34+
* @dataProvider AllSaintsDayDataProvider
35+
*
36+
* @param int $year the year for which All Saints' Day needs to be tested
37+
* @param DateTime $expected the expected date
38+
*
39+
* @throws ReflectionException
40+
*/
41+
public function testAllSaintsDay($year, $expected): void
42+
{
43+
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
44+
}
45+
46+
/**
47+
* Tests translated name of All Saints' Day.
48+
* @throws ReflectionException
49+
*/
50+
public function testTranslation(): void
51+
{
52+
$this->assertTranslatedHolidayName(
53+
self::REGION,
54+
self::HOLIDAY,
55+
$this->generateRandomYear(),
56+
[self::LOCALE => 'Toussaint']
57+
);
58+
}
59+
60+
/**
61+
* Tests type of the holiday defined in this test.
62+
* @throws ReflectionException
63+
*/
64+
public function testHolidayType(): void
65+
{
66+
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER);
67+
}
68+
69+
/**
70+
* Returns a list of random test dates used for assertion of All Saints' Day.
71+
*
72+
* @return array list of test dates for All Saints' Day
73+
* @throws Exception
74+
*/
75+
public function AllSaintsDayDataProvider(): array
76+
{
77+
return $this->generateRandomDates(11, 1, self::TIMEZONE);
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\tests\Switzerland\Fribourg;
14+
15+
use DateTime;
16+
use Exception;
17+
use ReflectionException;
18+
use Yasumi\Holiday;
19+
use Yasumi\tests\YasumiTestCaseInterface;
20+
21+
/**
22+
* Class for testing the day of the Assumption of Mary in Fribourg (Switzerland).
23+
*/
24+
class AssumptionOfMaryTest extends FribourgBaseTestCase implements YasumiTestCaseInterface
25+
{
26+
/**
27+
* The name of the holiday
28+
*/
29+
public const HOLIDAY = 'assumptionOfMary';
30+
31+
/**
32+
* Tests the day of the Assumption of Mary.
33+
*
34+
* @dataProvider AssumptionOfMaryDataProvider
35+
*
36+
* @param int $year the year for which the day of the Assumption of Mary needs to be tested
37+
* @param DateTime $expected the expected date
38+
*
39+
* @throws ReflectionException
40+
*/
41+
public function testAssumptionOfMary($year, $expected): void
42+
{
43+
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
44+
}
45+
46+
/**
47+
* Tests translated name of the day of the Assumption of Mary.
48+
* @throws ReflectionException
49+
*/
50+
public function testTranslation(): void
51+
{
52+
$this->assertTranslatedHolidayName(
53+
self::REGION,
54+
self::HOLIDAY,
55+
$this->generateRandomYear(),
56+
[self::LOCALE => 'Assomption']
57+
);
58+
}
59+
60+
/**
61+
* Tests type of the holiday defined in this test.
62+
* @throws ReflectionException
63+
*/
64+
public function testHolidayType(): void
65+
{
66+
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER);
67+
}
68+
69+
/**
70+
* Returns a list of random test dates used for assertion of the day of the Assumption of Mary.
71+
*
72+
* @return array list of test dates for the day of the Assumption of Mary
73+
* @throws Exception
74+
*/
75+
public function AssumptionOfMaryDataProvider(): array
76+
{
77+
return $this->generateRandomDates(8, 15, self::TIMEZONE);
78+
}
79+
}

0 commit comments

Comments
 (0)