Skip to content

Commit

Permalink
add new day of liberration in 2025 in Berlin
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoenlau committed Oct 21, 2024
1 parent e614fee commit b442564
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ changes.

### Added

- Added another day of liberation on 2025-05-08 ("Tag der Befreiung") in Berlin. See https://gesetze.berlin.de/bsbe/document/jlr-FeiertGBEV8P1

### Changed

- Holiday calculation methods in providers are now protected instead of private
- Holiday calculation methods in providers are now protected instead of private
to allow use in [custom providers](https://www.yasumi.dev/docs/cookbook/custom_provider/).
[\#331](https://github.com/azuyalabs/yasumi/issues/331)

Expand Down
11 changes: 7 additions & 4 deletions src/Yasumi/Provider/Germany/Berlin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ public function initialize(): void
$this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale));
}

if (2020 === $this->year) {
$this->addHoliday($this->dayOfLiberation($this->timezone, $this->locale));
if (2020 === $this->year || 2025 === $this->year) {
$this->addHoliday($this->dayOfLiberation($this->year, $this->timezone, $this->locale));
}
}

/**
* Day of Liberation.
*
* Day of Liberation (Tag der Befreiung) is celebrated on May 8 2020 to commemorate the 75th anniversary
* Day of Liberation (Tag der Befreiung) is celebrated on
* May 8 2020/2025 to commemorate the 75th/80th anniversary
* of the German Instrument of Surrender.
*
* @see https://de.wikipedia.org/wiki/Tag_der_Befreiung
*
* @param int $year the year in which Day of Liberation is celebrated
* @param string $timezone the timezone in which Day of Liberation is celebrated
* @param string $locale the locale for which Day of Liberation needs to be displayed in
* @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE,
Expand All @@ -78,14 +80,15 @@ public function initialize(): void
* @throws \Exception
*/
protected function dayOfLiberation(
int $year,
string $timezone,
string $locale,
string $type = Holiday::TYPE_OFFICIAL,
): Holiday {
return new Holiday(
'dayOfLiberation',
[],
new \DateTime('2020-05-08', DateTimeZoneFactory::getDateTimeZone($timezone)),
new \DateTime("{$year}-05-08", DateTimeZoneFactory::getDateTimeZone($timezone)),
$locale,
$type
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
use Yasumi\tests\HolidayTestCase;

/**
* Class for testing Day of Liberation 2020 in Berlin (Germany).
* Class for testing Day of Liberation in Berlin (Germany).
*/
class DayOfLiberation2020Test extends BerlinBaseTestCase implements HolidayTestCase
class DayOfLiberationTest extends BerlinBaseTestCase implements HolidayTestCase
{
/**
* The name of the holiday to be tested.
*/
public const HOLIDAY = 'dayOfLiberation';

/**
* The year in which the holiday takes place.
* The years in which the holiday takes place.
*/
public const YEAR = 2020;
public static $years = [2020, 2025];

/**
* Test the holiday defined in this test.
Expand All @@ -42,12 +42,14 @@ class DayOfLiberation2020Test extends BerlinBaseTestCase implements HolidayTestC
*/
public function testHolidayInYear(): void
{
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
self::YEAR,
new \DateTime(self::YEAR . '-05-08', new \DateTimeZone(self::TIMEZONE))
);
foreach (self::$years as $year) {
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new \DateTime($year . '-05-08', new \DateTimeZone(self::TIMEZONE))
);
}
}

/**
Expand All @@ -57,10 +59,11 @@ public function testHolidayInYear(): void
*/
public function testHolidayBeforeYear(): void
{
reset(self::$years);
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(1000, self::YEAR - 1)
$this->generateRandomYear(1000, current(self::$years) - 1)
);
}

Expand All @@ -71,10 +74,11 @@ public function testHolidayBeforeYear(): void
*/
public function testHolidayAfterYear(): void
{
end(self::$years);
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::YEAR + 1)
$this->generateRandomYear(current(self::$years) + 1)
);
}

Expand All @@ -83,10 +87,11 @@ public function testHolidayAfterYear(): void
*/
public function testTranslation(): void
{
reset(self::$years);
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
self::YEAR,
current(self::$years),
[self::LOCALE => 'Tag der Befreiung']
);
}
Expand All @@ -96,10 +101,11 @@ public function testTranslation(): void
*/
public function testHolidayType(): void
{
reset(self::$years);
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
self::YEAR,
current(self::$years),
Holiday::TYPE_OFFICIAL
);
}
Expand Down

0 comments on commit b442564

Please sign in to comment.