Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Georgia Provider. #245

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 231 additions & 0 deletions src/Yasumi/Provider/Georgia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<?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 <[email protected]>
*/

namespace Yasumi\Provider;

use Yasumi\Holiday;

/**
* Provider for all holidays in Georgia.
*
* @author Zurab Sardarov <[email protected]>
*/
class Georgia extends AbstractProvider
{
use CommonHolidays;
use ChristianHolidays;

public const PROCLAMATION_OF_INDEPENDENCE_YEAR = 1918;

public const APRIL_NINE_TRAGEDY_YEAR = 1989;

/**
* Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
* country or sub-region.
*/
public const ID = 'GE';

/**
* Initialize holidays for Georgia.
*
* @throws \InvalidArgumentException
* @throws \Exception
*/
public function initialize(): void
{
$this->timezone = 'Asia/Tbilisi';

$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->easter($this->year, $this->timezone, $this->locale));

$this->addSecondNewYearDay();
$this->addOrthodoxChristmasDay();
$this->addIndependenceDay();
$this->addMothersDay();
$this->addUnityDay();
$this->addVictoryDay();
$this->addStAndrewsDay();
$this->addOrthodoxEpiphanyDay();
$this->addMtskhetobaDay();
$this->addStMarysDay();
$this->addStGeorgesDay();
}

/**
* @throws \Exception
*/
public function calculateEaster(int $year, string $timezone): \DateTime
{
return $this->calculateOrthodoxEaster($year, $timezone);
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addOrthodoxChristmasDay(): void
{
$date = new \DateTime("{$this->year}-01-07", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('orthodoxChristmasDay', [
'en' => 'Orthodox Christmas Day',
'ka' => 'ქრისტეს შობა',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addIndependenceDay(): void
{
if ($this->year >= self::PROCLAMATION_OF_INDEPENDENCE_YEAR) {
$date = new \DateTime("{$this->year}-05-26", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('independenceDay', [
'en' => 'Independence Day',
'ka' => 'საქართველოს დამოუკიდებლობის დღე',
], $date, $this->locale));
}
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addUnityDay(): void
{
if ($this->year >= self::APRIL_NINE_TRAGEDY_YEAR) {
$date = new \DateTime("{$this->year}-04-09", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('unityDay', [
'en' => 'National Unity Day',
'ka' => 'ეროვნული ერთიანობის დღე',
], $date, $this->locale));
}
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addMothersDay(): void
{
$date = new \DateTime("{$this->year}-03-03", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('mothersDay', [
'en' => 'Mothers Day',
'ka' => 'დედის დღე',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addVictoryDay()
{
$date = new \DateTime("{$this->year}-05-09", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('victoryDay', [
'en' => 'Day of Victory over Fascism',
'ka' => 'ფაშიზმზე გამარჯვების დღე',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addStAndrewsDay(): void
{
$date = new \DateTime("{$this->year}-05-12", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('stAndrewsDay', [
'en' => 'Saint Andrew the First-Called Day',
'ka' => 'წმინდა ანდრია პირველწოდებულის ხსენების დღე',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addOrthodoxEpiphanyDay(): void
{
$date = new \DateTime("{$this->year}-01-19", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('orthodoxEpiphanyDay', [
'en' => 'Orthodox Epiphany Day',
'ka' => 'ნათლისღება',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addStMarysDay(): void
{
$date = new \DateTime("{$this->year}-08-28", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('stMarysDay', [
'en' => 'Saint Marys Day',
'ka' => 'მარიამობა',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addMtskhetobaDay(): void
{
$date = new \DateTime("{$this->year}-10-14", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('mtskhetobaDay', [
'en' => 'Day of Svetitskhoveli Cathedral',
'ka' => 'მცხეთობა',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addStGeorgesDay(): void
{
$date = new \DateTime("{$this->year}-11-23", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('stGeorgesDay', [
'en' => 'Saint Georges Day',
'ka' => 'გიორგობა',
], $date, $this->locale));
}

/**
* @throws \InvalidArgumentException
* @throws \Exception
*/
private function addSecondNewYearDay(): void
{
$date = new \DateTime("$this->year-01-02", new \DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('secondDayOfNewYear', [
'en' => 'Second day of the New Year',
'ka' => 'ბედობა',
], $date, $this->locale));
}
}
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/easter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'hr' => 'Uskrs',
'hu' => 'Húsvét',
'it' => 'Pasqua',
'ka' => 'აღდგომა',
'lt' => 'Velykos',
'lv' => 'Lieldienas',
'nb' => 'første påskedag',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/internationalWomensDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
return [
'de' => 'Internationaler Frauentag',
'en' => 'International Women’s Day',
'ka' => 'ქალთა საერთაშორისო დღე',
'ko' => '국제 여성의 날',
'ru' => 'Международный женский день',
'uk' => 'Міжнародний жіночий день',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/newYearsDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'hu' => 'Újév',
'it' => 'Capodanno',
'ja' => '元日',
'ka' => 'ახალი წელი',
'ko' => '새해',
'lt' => 'Naujųjų metų diena',
'lv' => 'Jaunais Gads',
Expand Down
63 changes: 63 additions & 0 deletions tests/Georgia/EasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Yasumi\tests\Georgia;

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

class EasterTest extends GeorgiaBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday to be tested.
*/
public const HOLIDAY = 'easter';

/**
* Tests the holiday defined in this test.
*
* @throws Exception
* @throws ReflectionException
*/
public function testHoliday(): void
{
$year = 2019;

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

/**
* Tests translated name of the holiday defined in this test.
*
* @throws ReflectionException
*/
public function testTranslation()
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'აღდგომა']
);
}

/**
* Tests type of the holiday defined in this test.
*
* @throws ReflectionException
*/
public function testHolidayType()
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL);
}
}
42 changes: 42 additions & 0 deletions tests/Georgia/GeorgiaBaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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 <[email protected]>
*/

namespace Yasumi\tests\Georgia;

use PHPUnit\Framework\TestCase;
use Yasumi\tests\YasumiBase;

/**
* Base class for test cases of the Georgia holiday provider.
*/
abstract class GeorgiaBaseTestCase extends TestCase
{
use YasumiBase;

/**
* Name of the country to be tested.
*/
public const REGION = 'Georgia';

/**
* Timezone in which this provider has holidays defined.
*/
public const TIMEZONE = 'Asia/Tbilisi';

/**
* Locale that is considered common for this provider.
*/
public const LOCALE = 'ka_GE';
}
Loading