Skip to content

Commit

Permalink
Improve Swiss providers (#233)
Browse files Browse the repository at this point in the history
Improve Swiss providers with links to official laws.
  • Loading branch information
qligier authored Oct 24, 2020
1 parent e2f37e6 commit a757a7c
Show file tree
Hide file tree
Showing 23 changed files with 853 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/Yasumi/Provider/Switzerland/Bern.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Provider for all holidays in Bern (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Canton_of_Bern
* @link https://www.fin.be.ch/fin/fr/index/personal/personalrecht/wdb.thema.212.html
*/
class Bern extends Switzerland
{
Expand Down
36 changes: 36 additions & 0 deletions src/Yasumi/Provider/Switzerland/Fribourg.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@

namespace Yasumi\Provider\Switzerland;

use DateTime;
use Yasumi\Exception\InvalidDateException;
use Yasumi\Exception\UnknownLocaleException;
use Yasumi\Holiday;
use Yasumi\Provider\ChristianHolidays;
use Yasumi\Provider\DateTimeZoneFactory;
use Yasumi\Provider\Switzerland;

/**
* Provider for all holidays in Fribourg (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Canton_of_Fribourg
* @link https://www.fr.ch/travail-et-entreprises/employes/jour-ferie-jour-chome-quelle-difference
*/
class Fribourg extends Switzerland
{
Expand All @@ -45,11 +48,44 @@ public function initialize(): void
{
parent::initialize();

// For the whole canton
$this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));

// For the roman catholic communes
$this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));

// For the reformed evangelical communes
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->calculateBerchtoldsTag($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
$this->calculateDecember26th($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
}

/**
* December 26th
*
* @throws InvalidDateException
* @throws \InvalidArgumentException
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateDecember26th(): void
{
$this->addHoliday(new Holiday(
'december26th',
[
'en' => 'December 26th',
'fr' => '26 décembre',
],
new DateTime($this->year . '-12-26', DateTimeZoneFactory::getDateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_OTHER
));
}
}
1 change: 1 addition & 0 deletions src/Yasumi/Provider/Switzerland/Geneva.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Provider for all holidays in Geneva (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Canton_of_Geneva
* @link https://www.ge.ch/legislation/rsg/f/s/rsg_j1_45.html
*/
class Geneva extends Switzerland
{
Expand Down
4 changes: 4 additions & 0 deletions src/Yasumi/Provider/Switzerland/Jura.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Provider for all holidays in Jura (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Canton_of_Jura
* @link https://rsju.jura.ch/fr/viewdocument.html?idn=20105&id=26766
*/
class Jura extends Switzerland
{
Expand Down Expand Up @@ -60,11 +61,14 @@ public function initialize(): void
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));

$this->calculateBerchtoldsTag();
$this->calculatePlebisciteJurassien();
$this->calculateBettagsMontag();
}

/**
Expand Down
63 changes: 60 additions & 3 deletions src/Yasumi/Provider/Switzerland/Neuchatel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* Provider for all holidays in Neuchâtel (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Canton_of_Neuch%C3%A2tel
* @link http://rsn.ne.ch/DATA/program/books/RSN2017/20171/htm/94102.htm
* @link https://www.ne.ch/themes/travail/Pages/jours-feries.aspx
*/
class Neuchatel extends Switzerland
{
Expand Down Expand Up @@ -54,15 +56,26 @@ public function initialize(): void
$this->locale,
Holiday::TYPE_OTHER
));
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));

$this->calculateBerchtoldsTag();
$this->calculateBettagsMontag();
$this->calculateInstaurationRepublique();

$newYearsDay = $this->newYearsDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
$this->addHoliday($newYearsDay);
if ($newYearsDay->format('N') === '7') {
// If the New Year's Day is a sunday, the next day is an holiday
$this->calculateJanuary2nd();
}

$christmasDay = $this->christmasDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER);
$this->addHoliday($christmasDay);
if ($christmasDay->format('N') === '7') {
// If the Christmas Day is a sunday, the next day is an holiday
$this->calculateDecember26th();
}
}

/**
Expand All @@ -89,4 +102,48 @@ private function calculateInstaurationRepublique(): void
));
}
}

/**
* January 2nd
*
* @throws InvalidDateException
* @throws \InvalidArgumentException
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateJanuary2nd(): void
{
$this->addHoliday(new Holiday(
'january2nd',
[
'en' => 'January 2nd',
'fr' => '2 janvier',
],
new DateTime($this->year . '-01-02', DateTimeZoneFactory::getDateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_OTHER
));
}

/**
* December 26th
*
* @throws InvalidDateException
* @throws \InvalidArgumentException
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateDecember26th(): void
{
$this->addHoliday(new Holiday(
'december26th',
[
'en' => 'December 26th',
'fr' => '26 décembre',
],
new DateTime($this->year . '-12-26', DateTimeZoneFactory::getDateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_OTHER
));
}
}
1 change: 1 addition & 0 deletions src/Yasumi/Provider/Switzerland/Valais.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Provider for all holidays in Valais (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Valais
* @link https://www.vs.ch/web/spt/jours-feries
*/
class Valais extends Switzerland
{
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/Provider/Switzerland/Vaud.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Provider for all holidays in Vaud (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Vaud
* @link https://www.vd.ch/themes/formation/jours-feries-et-vacances-scolaires/
*/
class Vaud extends Switzerland
{
Expand Down
3 changes: 1 addition & 2 deletions src/Yasumi/Provider/Switzerland/Zurich.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Provider for all holidays in Zürich (Switzerland).
*
* @link https://en.wikipedia.org/wiki/Canton_of_Z%C3%BCrich
* @link https://www.zh.ch/de/wirtschaft-arbeit/arbeitsbedingungen/arbeitsssicherheit-gesundheitsschutz/arbeits-ruhezeiten/feiertage.html
*/
class Zurich extends Switzerland
{
Expand Down Expand Up @@ -58,7 +59,5 @@ public function initialize(): void
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));

$this->calculateBerchtoldsTag();
}
}
79 changes: 79 additions & 0 deletions tests/Switzerland/Fribourg/AllSaintsDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php declare(strict_types=1);
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2020 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/

namespace Yasumi\tests\Switzerland\Fribourg;

use DateTime;
use Exception;
use ReflectionException;
use Yasumi\Holiday;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class for testing All Saints' Day in Fribourg (Switzerland).
*/
class AllSaintsDayTest extends FribourgBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
public const HOLIDAY = 'allSaintsDay';

/**
* Tests All Saints' Day.
*
* @dataProvider AllSaintsDayDataProvider
*
* @param int $year the year for which All Saints' Day needs to be tested
* @param DateTime $expected the expected date
*
* @throws ReflectionException
*/
public function testAllSaintsDay($year, $expected): void
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* Tests translated name of All Saints' Day.
* @throws ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'Toussaint']
);
}

/**
* Tests type of the holiday defined in this test.
* @throws ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER);
}

/**
* Returns a list of random test dates used for assertion of All Saints' Day.
*
* @return array list of test dates for All Saints' Day
* @throws Exception
*/
public function AllSaintsDayDataProvider(): array
{
return $this->generateRandomDates(11, 1, self::TIMEZONE);
}
}
79 changes: 79 additions & 0 deletions tests/Switzerland/Fribourg/AssumptionOfMaryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php declare(strict_types=1);
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2020 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/

namespace Yasumi\tests\Switzerland\Fribourg;

use DateTime;
use Exception;
use ReflectionException;
use Yasumi\Holiday;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class for testing the day of the Assumption of Mary in Fribourg (Switzerland).
*/
class AssumptionOfMaryTest extends FribourgBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
public const HOLIDAY = 'assumptionOfMary';

/**
* Tests the day of the Assumption of Mary.
*
* @dataProvider AssumptionOfMaryDataProvider
*
* @param int $year the year for which the day of the Assumption of Mary needs to be tested
* @param DateTime $expected the expected date
*
* @throws ReflectionException
*/
public function testAssumptionOfMary($year, $expected): void
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* Tests translated name of the day of the Assumption of Mary.
* @throws ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'Assomption']
);
}

/**
* Tests type of the holiday defined in this test.
* @throws ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OTHER);
}

/**
* Returns a list of random test dates used for assertion of the day of the Assumption of Mary.
*
* @return array list of test dates for the day of the Assumption of Mary
* @throws Exception
*/
public function AssumptionOfMaryDataProvider(): array
{
return $this->generateRandomDates(8, 15, self::TIMEZONE);
}
}
Loading

0 comments on commit a757a7c

Please sign in to comment.