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

update ukraine holidays #202

Merged
merged 6 commits into from
Feb 5, 2020
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
- Holiday providers for states of Austria. [\#182](https://github.com/azuyalabs/yasumi/pull/182) ([aprog](https://github.com/aprog))
- Added missing return (correct) and parameter types in various methods.
- Day of Liberation (Tag der Befreiung) is an one-time official holiday in 2020 in Berlin (Germany).
- Catholic Christmas Day is a new official holiday since 2017 in the Ukraine. [\#202](https://github.com/azuyalabs/yasumi/pull/202)

### Changed
- Holiday names in Danish, Dutch, and Norwegian are no longer capitalized. [\#185](https://github.com/azuyalabs/yasumi/pull/185) ([c960657](https://github.com/c960657))
Expand All @@ -21,12 +22,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
- Refactored various conditional structures.
- Changed signature of some methods as parameters with defaults should come after required parameters.
- Updated third party dependencies.
- Second International Workers Day was an official holiday only until 2018. [\#202](https://github.com/azuyalabs/yasumi/pull/202)

### Fixed
- Fixed issue if the next working day happens to be in the next year (i.e. not in the year of the Yasumi instance) [\#192](https://github.com/azuyalabs/yasumi/issues/192) ([tniemann](https://github.com/tniemann))
- Fixed issue if the previous working day happens to be in the previous year (i.e. not in the year of the Yasumi instance)
- Fix locale fallback for substitute holidays [\#180](https://github.com/azuyalabs/yasumi/pull/180) ([c960657](https://github.com/c960657))
- Fixed compound conditions that are always true by simplifying the condition steps.
- Fixed Ukraine holidays on weekends. These days need to be substituted. [\#202](https://github.com/azuyalabs/yasumi/pull/202)

### Removed
- PHP 7.1 Support, as it has reached its end of life.
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/Holiday.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1);

/**
* This file is part of the Yasumi package.
*
Expand Down
77 changes: 76 additions & 1 deletion src/Yasumi/Provider/Ukraine.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
HeinrichConvidera marked this conversation as resolved.
Show resolved Hide resolved

/**
* This file is part of the Yasumi package.
*
Expand All @@ -15,6 +16,7 @@
use Yasumi\Exception\InvalidDateException;
use Yasumi\Exception\UnknownLocaleException;
use Yasumi\Holiday;
use Yasumi\SubstituteHoliday;

/**
* Provider for all holidays in Ukraine.
Expand Down Expand Up @@ -48,7 +50,8 @@ public function initialize(): void
$this->timezone = 'Europe/Kiev';

// Add common holidays
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
// New Years Day will not be substituted to an monday if it's on a weekend!
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale), false);
$this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale));

Expand All @@ -63,6 +66,42 @@ public function initialize(): void
$this->calculateConstitutionDay();
$this->calculateIndependenceDay();
$this->calculateDefenderOfUkraineDay();
$this->calculateCatholicChristmasDay();
}

/**
* Adds a holiday to the holidays providers (i.e. country/state) list of holidays.
*
* @param Holiday $holiday Holiday instance (representing a holiday) to be added to the internal list
* of holidays of this country.
* @param bool $substitutable Holidays on a weekend will be substituted to the next monday.
*
* @throws InvalidDateException
* @throws UnknownLocaleException
* @throws \InvalidArgumentException
* @throws \Exception
*/
public function addHoliday(Holiday $holiday, bool $substitutable = true): void
{
parent::addHoliday($holiday);

if (!$substitutable) {
return;
}

// Substitute holiday is on the next available weekday
// if a holiday falls on a Saturday or Sunday.
if ($this->isWeekendDay($holiday)) {
$date = clone $holiday;
$date->modify('next monday');

parent::addHoliday(new SubstituteHoliday(
HeinrichConvidera marked this conversation as resolved.
Show resolved Hide resolved
$holiday,
[],
$date,
$this->locale
));
}
}

/**
Expand All @@ -85,6 +124,7 @@ private function calculateChristmasDay(): void

/**
* International Workers' Day.
HeinrichConvidera marked this conversation as resolved.
Show resolved Hide resolved
* National holiday until 2018.
*
* @link https://en.wikipedia.org/wiki/International_Workers%27_Day#Ukraine
*
Expand All @@ -95,6 +135,10 @@ private function calculateChristmasDay(): void
*/
private function calculateSecondInternationalWorkersDay(): void
HeinrichConvidera marked this conversation as resolved.
Show resolved Hide resolved
{
if ($this->year >= 2018) {
return;
}

$this->addHoliday(new Holiday('secondInternationalWorkersDay', [
'uk' => 'День міжнародної солідарності трудящих',
'ru' => 'День международной солидарности трудящихся',
Expand Down Expand Up @@ -222,4 +266,35 @@ public function calculateEaster(int $year, string $timezone): \DateTime
{
return $this->calculateOrthodoxEaster($year, $timezone);
}

/**
* Catholic Christmas Day.
* (since 2017 instead of International Workers' Day 2. May)
*
* @link https://en.wikipedia.org/wiki/Christmas_in_Ukraine
*
* @throws InvalidDateException
* @throws \InvalidArgumentException
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateCatholicChristmasDay(): void
{
if ($this->year < 2017) {
return;
}

$this->addHoliday(
new Holiday(
'catholicChristmasDay',
[
'uk' => 'Католицький день Різдва',
'ru' => 'Католическое рождество',
],
new \DateTime("$this->year-12-25", new \DateTimeZone($this->timezone)),
$this->locale
),
false // Catholic Christmas Day will not be substituted to an monday if it's on a weekend!
);
}
}
3 changes: 1 addition & 2 deletions tests/Base/WeekendTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
declare(strict_types=1);
<?php declare(strict_types=1);

/**
* This file is part of the Yasumi package.
Expand Down
104 changes: 104 additions & 0 deletions tests/Ukraine/CatholicChristmasDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php declare(strict_types=1);
HeinrichConvidera marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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 <me@sachatelgenhof.com>
*/

namespace Yasumi\tests\Ukraine;

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

/**
* Class CatholicChristmasDayTest
* @package Yasumi\tests\Ukraine
*/
class CatholicChristmasDayTest extends UkraineBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
public const HOLIDAY = 'catholicChristmasDay';

/**
* Tests Catholic Christmas Day.
*
* @dataProvider CatholicChristmasDayDataProvider
*
* @param int $year the year for which International Workers' Day needs to be tested
* @param DateTime $expected the expected date
*
* @throws ReflectionException
*/
public function testCatholicChristmasDay($year, $expected)
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* Tests Catholic Christmas Day before 2017.
* @throws ReflectionException
*/
public function testNoCatholicChristmasDayBefore2017()
{
$year = $this->generateRandomYear(null, 2016);
$holidays = Yasumi::create(self::REGION, $year);
$holiday = $holidays->getHoliday(self::HOLIDAY);

$this->assertNull($holiday);

unset($year, $holiday, $holidays);
}

/**
* Tests translated name of the holiday defined in this test.
* @throws ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(2017),
[self::LOCALE => 'Католицький день Різдва']
);
}

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

/**
* Returns a list of random test dates used for assertion of Catholic Christmas Day.
*
* @return array list of test dates for Catholic Christmas Day
* @throws Exception
*/
public function CatholicChristmasDayDataProvider(): array
{
$data = [];

for ($y = 0; $y < 10; $y++) {
$year = $this->generateRandomYear(2017);
$data[] = [$year, new \DateTime("$year-12-25", new \DateTimeZone(self::TIMEZONE))];
}

return $data;
}
}
36 changes: 32 additions & 4 deletions tests/Ukraine/SecondInternationalWorkersDayTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1);

/**
* This file is part of the Yasumi package.
*
Expand All @@ -13,10 +14,10 @@
namespace Yasumi\tests\Ukraine;

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

/**
* Class SecondInternationalWorkersDayTest
Expand Down Expand Up @@ -44,6 +45,21 @@ public function testSecondInternationalWorkersDay($year, $expected)
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* Tests International Workers' Day since 2018.
* @throws ReflectionException
*/
public function testNoSecondInternationalWorkersDaySince2018()
{
$year = $this->generateRandomYear(2018);
$holidays = Yasumi::create(self::REGION, $year);
$holiday = $holidays->getHoliday(self::HOLIDAY);

$this->assertNull($holiday);

unset($year, $holiday, $holidays);
}

/**
* Tests translated name of the holiday defined in this test.
* @throws ReflectionException
Expand All @@ -53,7 +69,7 @@ public function testTranslation(): void
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
$this->generateRandomYear(null, 2017),
[self::LOCALE => 'День міжнародної солідарності трудящих']
);
}
Expand All @@ -64,7 +80,12 @@ public function testTranslation(): void
*/
public function testHolidayType(): void
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OFFICIAL);
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(null, 2017),
Holiday::TYPE_OFFICIAL
);
}

/**
Expand All @@ -75,6 +96,13 @@ public function testHolidayType(): void
*/
public function SecondInternationalWorkersDayDataProvider(): array
{
return $this->generateRandomDates(5, 2, self::TIMEZONE);
$data = [];

for ($y = 0; $y < 10; $y++) {
$year = $this->generateRandomYear(null, 2017);
$data[] = [$year, new \DateTime("$year-05-02", new \DateTimeZone(self::TIMEZONE))];
stelgenhof marked this conversation as resolved.
Show resolved Hide resolved
}

return $data;
}
}
Loading