Skip to content

Commit

Permalink
Turkey (#250)
Browse files Browse the repository at this point in the history
This will add Turkey as a new Holiday Provider. Note that Islamic holidays are not yet included. Islamic holidays are a bit more complex and will need some time to implement these at a later stage.
  • Loading branch information
stelgenhof committed May 26, 2021
1 parent 6ade29d commit 9b06458
Show file tree
Hide file tree
Showing 15 changed files with 916 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -59,7 +59,7 @@
},
"scripts": {
"format": "./vendor/bin/php-cs-fixer fix",
"phpstan": "vendor/bin/phpstan --level=5 analyse src tests",
"phpstan": "vendor/bin/phpstan analyse",
"psalm": "vendor/bin/psalm --threads=2",
"phan": "vendor/bin/phan",
"test": "vendor/bin/phpunit",
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
@@ -0,0 +1,9 @@
parameters:
level: 5
paths:
- src
- tests
ignoreErrors:
-
message: '#Comparison operation "<=" between [0-9]+ and int<[0-9]+, max> is always true.#'
path: src/Yasumi/Provider/Turkey.php
4 changes: 4 additions & 0 deletions phpunit.xml
Expand Up @@ -162,6 +162,10 @@
<testsuite name="Switzerland">
<directory suffix="Test.php">./tests/Switzerland</directory>
</testsuite>
<!-- Test Suite for holidays in Turkey -->
<testsuite name="Turkey">
<directory suffix="Test.php">./tests/Turkey</directory>
</testsuite>
<!-- Test Suite for holidays in United States -->
<testsuite name="USA">
<directory suffix="Test.php">./tests/USA</directory>
Expand Down
187 changes: 187 additions & 0 deletions src/Yasumi/Provider/Turkey.php
@@ -0,0 +1,187 @@
<?php

declare(strict_types=1);
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2021 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me@sachatelgenhof.com>
*/

namespace Yasumi\Provider;

use Yasumi\Exception\InvalidDateException;
use Yasumi\Exception\UnknownLocaleException;
use Yasumi\Holiday;

/**
* Note: Any Islamic holidays are not part of this provider yet. Islamic holidays are quite complex and at first,
* only other holidays are implemented.
*/
class Turkey extends AbstractProvider
{
use CommonHolidays;

/** {@inheritdoc} */
public const ID = 'TR';

/**
* @throws InvalidDateException
* @throws \InvalidArgumentException
* @throws UnknownLocaleException
* @throws \Exception
*/
public function initialize(): void
{
$this->timezone = 'Europe/Istanbul';

// Add common holidays
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
$this->addNationalSovereigntyDay();
$this->addLabourDay();
$this->addCommemorationOfAtaturk();
$this->addDemocracyDay();
$this->addVictoryDay();
$this->addRepublicDay();
}

/** {@inheritdoc} */
public function getSources(): array
{
return [
'https://en.wikipedia.org/wiki/Public_holidays_in_Turkey',
'https://tr.wikipedia.org/wiki/T%C3%BCrkiye%27deki_resm%C3%AE_tatiller',
];
}

/**
* @throws \Exception
*/
private function addLabourDay(): void
{
$this->addHoliday(new Holiday('labourDay', [
'tr' => 'Emek ve Dayanışma Günü',
], new \DateTime("$this->year-05-01", new \DateTimeZone($this->timezone)), $this->locale));
}

/**
* Commemoration of the first opening of the Grand National Assembly of Turkey at Ankara in 1920.
* Dedicated to the children.
*
* Not sure if 1920 is the first year of celebration as above source mentions Law No. 3466 that "May 19" was
* made official June 20, 1938.
*
* @see https://en.wikipedia.org/wiki/Commemoration_of_Atat%C3%BCrk,_Youth_and_Sports_Day
*
* @throws \Exception
*/
private function addCommemorationOfAtaturk(): void
{
if (1920 > $this->year) {
return;
}

$this->addHoliday(new Holiday('commemorationAtaturk', [
'tr' => 'Atatürk’ü Anma, Gençlik ve Spor Bayramı',
], new \DateTime("$this->year-05-19", new \DateTimeZone($this->timezone)), $this->locale));
}

/**
* National Sovereignty and Children's Day (Turkish: Ulusal Egemenlik ve Çocuk Bayramı) is a public holiday in
* Turkey commemorating the foundation of the Grand National Assembly of Turkey, on 23 April 1920.
* Since 1927, the holiday has also been celebrated as a children's day.
*
* @see https://en.wikipedia.org/wiki/National_Sovereignty_and_Children%27s_Day
*
* @throws \Exception
*/
private function addNationalSovereigntyDay(): void
{
if (1922 > $this->year) {
return;
}

$holidayName = 'Ulusal Egemenlik Bayramı';

// In 1981 this day was officially named 'Ulusal Egemenlik ve Çocuk Bayramı'
if (1981 <= $this->year) {
$holidayName = 'Ulusal Egemenlik ve Çocuk Bayramı';
}

$this->addHoliday(new Holiday('nationalSovereigntyDay', [
'tr' => $holidayName,
], new \DateTime("$this->year-04-23", new \DateTimeZone($this->timezone)), $this->locale));
}

/**
* The Democracy and National Unity Day of Turkey (Turkish: Demokrasi ve Milli Birlik Günü) is one of the public
* holidays in Turkey, commemorating the national unity against the coup d'état attempt for democracy in 2016.
*
* @see https://en.wikipedia.org/wiki/Democracy_and_National_Unity_Day
*
* @throws \Exception
*/
private function addDemocracyDay(): void
{
if (2017 > $this->year) {
return;
}

$this->addHoliday(new Holiday('democracyDay', [
'tr' => 'Demokrasi ve Millî Birlik Günü',
], new \DateTime("$this->year-07-15", new \DateTimeZone($this->timezone)), $this->locale));
}

/**
* Victory Day (Turkish: Zafer Bayramı), also known as Turkish Armed Forces Day, is a public holiday in Turkey
* commemorating the decisive victory in the Battle of Dumlupınar, on 30 August 1922.
*
* @see https://en.wikipedia.org/wiki/Victory_Day_(Turkey)
*
* @throws \Exception
*/
private function addVictoryDay(): void
{
if (1923 > $this->year) {
return;
}

$holidayType = Holiday::TYPE_OFFICIAL;

// Victory Day has been celebrated as an official holiday since 1926, and was first celebrated on 30 August
// 1923.
if (1923 <= $this->year && 1926 > $this->year) {
$holidayType = Holiday::TYPE_OBSERVANCE;
}

$this->addHoliday(new Holiday('victoryDay', [
'tr' => 'Zafer Bayramı',
], new \DateTime("$this->year-08-30", new \DateTimeZone($this->timezone)), $this->locale, $holidayType));
}

/**
* Republic Day (Turkish: Cumhuriyet Bayramı) is a public holiday in Turkey commemorating the proclamation of the
* Republic of Turkey, on 29 October 1923. The annual celebrations start at 1:00 pm on 28 October and continue for
* 35 hours.
*
* Note: the start of the celebrations the preceding day at 1:00pm is not covered in this library.
*
* @see https://en.wikipedia.org/wiki/Republic_Day_(Turkey)
*
* @throws \Exception
*/
private function addRepublicDay(): void
{
if (1923 > $this->year) {
return;
}

$this->addHoliday(new Holiday('republicDay', [
'tr' => 'Cumhuriyet Bayramı',
], new \DateTime("$this->year-10-29", new \DateTimeZone($this->timezone)), $this->locale));
}
}
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/labourDay.php
Expand Up @@ -22,4 +22,5 @@
'nl' => 'Dag van de arbeid',
'sk' => 'Sviatok práce',
'fr' => 'Fête du travail',
'tr' => 'Emek ve Dayanışma Günü',
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/newYearsDay.php
Expand Up @@ -47,5 +47,6 @@
'ru' => 'Новый год',
'sk' => 'Nový rok',
'sv' => 'nyårsdagen',
'tr' => 'Yılbaşı',
'uk' => 'Новий Рік',
];
75 changes: 75 additions & 0 deletions tests/Turkey/CommemorationOfAtaturkTest.php
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2021 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me@sachatelgenhof.com>
*/

namespace Yasumi\tests\Turkey;

use ReflectionException;
use Yasumi\Holiday;
use Yasumi\tests\HolidayTestCase;
use Yasumi\Yasumi;

class CommemorationOfAtaturkTest extends TurkeyBaseTestCase implements HolidayTestCase
{
public const HOLIDAY = 'commemorationAtaturk';

public const ESTABLISHMENT_YEAR = 1920;

/**
* @throws ReflectionException
*/
public function testHolidayBeforeEstablishment(): void
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1)
);
}

/**
* @throws ReflectionException
* @throws \Exception
*/
public function testHolidayOnAfterEstablishment(): void
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new \DateTime("$year-5-19", new \DateTimeZone(self::TIMEZONE))
);
}

/**
* @throws ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
[self::LOCALE => 'Atatürk’ü Anma, Gençlik ve Spor Bayramı']
);
}

/**
* @throws ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(self::ESTABLISHMENT_YEAR), Holiday::TYPE_OFFICIAL);
}
}
80 changes: 80 additions & 0 deletions tests/Turkey/DemocracyDayTest.php
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);
/*
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2021 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me@sachatelgenhof.com>
*/

namespace Yasumi\tests\Turkey;

use ReflectionException;
use Yasumi\Holiday;
use Yasumi\tests\HolidayTestCase;
use Yasumi\Yasumi;

class DemocracyDayTest extends TurkeyBaseTestCase implements HolidayTestCase
{
public const HOLIDAY = 'democracyDay';

public const ESTABLISHMENT_YEAR = 2017;

/**
* @throws ReflectionException
*/
public function testHoliday(): void
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);

$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new \DateTime("$year-7-15", new \DateTimeZone(self::TIMEZONE))
);
}

/**
* @throws ReflectionException
*/
public function testHolidayBeforeEstablishment(): void
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(Yasumi::YEAR_LOWER_BOUND, self::ESTABLISHMENT_YEAR - 1)
);
}

/**
* @throws ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
[self::LOCALE => 'Demokrasi ve Millî Birlik Günü']
);
}

/**
* @throws ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
Holiday::TYPE_OFFICIAL
);
}
}

0 comments on commit 9b06458

Please sign in to comment.