Skip to content

Commit

Permalink
Add initial code for the Bulgaria provider
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Telgenhof <[email protected]>
  • Loading branch information
stelgenhof committed Oct 26, 2024
1 parent 004ce27 commit 655016d
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/Yasumi/Provider/Bulgaria.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

namespace Yasumi\Provider;

use Yasumi\Holiday;

class Bulgaria extends AbstractProvider
{
use CommonHolidays;
use ChristianHolidays;

public const ID = 'BG';

public function initialize(): void
{
$this->timezone = 'Europe/Sofia';

// // Add common holidays
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
// $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
//
// // Add Catholic holidays
// $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale));
// $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale));
// $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
//
// // Add Orthodox holidays
//
// $this->addHoliday(new Holiday('orthodoxChristmasDay', [
// 'en' => 'Orthodox Christmas Day',
// 'bs_Latn' => 'Pravoslavni Božić',
// ], new \DateTime("{$this->year}-01-07", DateTimeZoneFactory::getDateTimeZone($this->timezone))));
//
// /*
// * Independence Day
// */
// if ($this->year >= 1992) {
// $this->addHoliday(new Holiday('independenceDay', [
// 'en' => 'Independence Day',
// 'bs_Latn' => 'Dan Nezavisnosti',
// ], new \DateTime("{$this->year}-3-1", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale));
// }
//
// /*
// * Bulgarian Statehood Day
// */
// if ($this->year >= 1943) {
// $this->addHoliday(new Holiday('statehoodDay', [
// 'en' => 'Statehood Day',
// 'bs_Latn' => 'Dan državnosti',
// ], new \DateTime("{$this->year}-11-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale));
// }
//
// /*
// * Day after New Years Day
// */
// $this->addHoliday(new Holiday('dayAfterNewYearsDay', [
// 'en' => 'Day after New Year’s Day',
// 'bs_Latn' => 'Nova godina - drugi dan',
// ], new \DateTime("{$this->year}-01-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale));
//
// /*
// * Second Labour day
// */
// $this->addHoliday(new Holiday('secondLabourDay', [
// 'en' => 'Second Labour Day',
// 'bs_Latn' => 'Praznik rada - drugi dan',
// ], new \DateTime("{$this->year}-05-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale));
}

public function getSources(): array
{
return [
'https://en.wikipedia.org/wiki/Public_holidays_in_Bulgaria',
'https://bg.wikipedia.org/wiki/%D0%9E%D1%84%D0%B8%D1%86%D0%B8%D0%B0%D0%BB%D0%BD%D0%B8_%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8_%D0%B2_%D0%91%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D0%B8%D1%8F',
];
}
}
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/newYearsDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Translations for New Year's Day
return [
'bs_Latn' => 'Nova godina',
'bg' => 'Нова година',
'ca' => 'Cap d’any',
'cs' => 'Nový rok',
'cy' => 'Dydd Calan',
Expand Down
32 changes: 32 additions & 0 deletions tests/Bulgaria/BulgariaBaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

namespace Yasumi\tests\Bulgaria;

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

abstract class BulgariaBaseTestCase extends TestCase
{
use YasumiBase;

public const REGION = 'Bulgaria';

public const TIMEZONE = 'Europe/Sofia';

public const LOCALE = 'bg_BG';
}
72 changes: 72 additions & 0 deletions tests/Bulgaria/BulgariaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

namespace Yasumi\tests\Bulgaria;

use Yasumi\Holiday;
use Yasumi\tests\ProviderTestCase;

class BulgariaTest extends BulgariaBaseTestCase implements ProviderTestCase
{
protected int $year;

protected function setUp(): void
{
$this->year = $this->generateRandomYear();
}

public function testOfficialHolidays(): void
{
$this->assertDefinedHolidays([
'newYearsDay',
// 'dayAfterNewYearsDay',
// 'internationalWorkersDay',
// 'secondLabourDay',
// 'christmasDay',
// 'easter',
// 'allSaintsDay',
// 'statehoodDay',
// 'independenceDay',
// 'orthodoxChristmasDay',
], self::REGION, $this->year, Holiday::TYPE_OFFICIAL);
}

public function testObservedHolidays(): void
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE);
}

public function testSeasonalHolidays(): void
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON);
}

public function testBankHolidays(): void
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK);
}

public function testOtherHolidays(): void
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER);
}

public function testSources(): void
{
$this->assertSources(self::REGION, 2);
}
}
54 changes: 54 additions & 0 deletions tests/Bulgaria/NewYearsDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the 'Yasumi' package.
*
* The easy PHP Library for calculating holidays.
*
* Copyright (c) 2015 - 2024 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me at sachatelgenhof dot com>
*/

namespace Yasumi\tests\Bulgaria;

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

class NewYearsDayTest extends BulgariaBaseTestCase implements HolidayTestCase
{
public const HOLIDAY = 'newYearsDay';

/**
* @dataProvider HolidayDataProvider
*/
public function testHoliday(int $year, \DateTimeInterface $expected): void
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

public function HolidayDataProvider(): array
{
return $this->generateRandomDates(1, 1, self::TIMEZONE);
}

public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'Нова година']
);
}

public function testHolidayType(): void
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL);
}
}

0 comments on commit 655016d

Please sign in to comment.