Skip to content

Commit

Permalink
Merge pull request #48 from umulmrum/feature/latvia
Browse files Browse the repository at this point in the history
Feature/latvia
  • Loading branch information
umulmrum authored Jun 10, 2024
2 parents dbd2d62 + e1a6445 commit 40b9a83
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Holidays for Estonia
- Holidays for Latvia
- Compensatory days can now be calculated automatically (providers only provide configuration). See the section on adding
a new country or region in README.md for details.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ Currently only the Gregorian calendar is supported, for years < 10000.
- Iceland
- Ireland
- Italy (incl. South Tyrol)
- Latvia
- Liechtenstein
- Luxembourg
- Mexico
Expand Down
2 changes: 1 addition & 1 deletion doc/world.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions res/trans/umulmrum_holiday.de.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
'portugal_republic_day' => 'Tag der Republik',
'portugal_restoration_of_independence' => 'Wiederherstellung der Unabhängigkeit',
'proclamation_day' => 'Proclamation Day',
'proclamation_day_of_the_republic_of_latvia' => 'Proclamation Day of the Republic of Latvia',
'proclamation_day_of_the_republic_of_latvia_compensatory' => 'Proclamation Day of the Republic of Latvia (Ausgleich)',
'queens_day' => 'Königinnentag',
'reconciliation_day' => 'Reconciliation Day',
'recreation_day' => 'Recreation Day',
Expand All @@ -189,6 +191,8 @@
'republic_day' => 'Tag der Republik',
'republic_proclamation_day' => 'Tag der Ausrufung der Republik',
'restoration_day_of_the_independent_czech_state' => 'Tag der Erneuerung des selbständigen tschechischen Staates',
'restoration_of_independence_day' => 'Restoration of Independence Day',
'restoration_of_independence_day_compensatory' => 'Restoration of Independence Day (Ausgleich)',
'revolution_day' => 'Tag der Revolution',
'royal_hobart_regatta' => 'Royal Hobart Regatta',
'russia_day' => 'Tag Russlands',
Expand Down
4 changes: 4 additions & 0 deletions res/trans/umulmrum_holiday.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
'portugal_republic_day' => 'Republic Day',
'portugal_restoration_of_independence' => 'Restoration of Independence',
'proclamation_day' => 'Proclamation Day',
'proclamation_day_of_the_republic_of_latvia' => 'Proclamation Day of the Republic of Latvia',
'proclamation_day_of_the_republic_of_latvia_compensatory' => 'Proclamation Day of the Republic of Latvia (compensatory)',
'queens_day' => 'Queen\'s Day',
'reconciliation_day' => 'Reconciliation Day',
'recreation_day' => 'Recreation Day',
Expand All @@ -189,6 +191,8 @@
'republic_day' => 'Republic Day',
'republic_proclamation_day' => 'Republic Proclamation Day',
'restoration_day_of_the_independent_czech_state' => 'Restoration Day of the Independent Czech State',
'restoration_of_independence_day' => 'Restoration of Independence Day',
'restoration_of_independence_day_compensatory' => 'Restoration of Independence Day (compensatory)',
'revolution_day' => 'Revolution Day',
'royal_hobart_regatta' => 'Royal Hobart Regatta',
'russia_day' => 'Russia Day',
Expand Down
6 changes: 6 additions & 0 deletions src/Constant/HolidayName.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ final class HolidayName
public const REPUBLIC_DAY = 'republic_day';
public const TRICOLOUR_DAY = 'tricolour_day';

// Latvia
public const PROCLAMATION_DAY_OF_THE_REPUBLIC_OF_LATVIA = 'proclamation_day_of_the_republic_of_latvia';
public const PROCLAMATION_DAY_OF_THE_REPUBLIC_OF_LATVIA_COMPENSATORY = 'proclamation_day_of_the_republic_of_latvia_compensatory';
public const RESTORATION_OF_INDEPENDENCE_DAY = 'restoration_of_independence_day';
public const RESTORATION_OF_INDEPENDENCE_DAY_COMPENSATORY = 'restoration_of_independence_day_compensatory';

// Luxembourg
public const EUROPE_DAY = 'europe_day';
public const GRAND_DUKES_OFFICIAL_BIRTHDAY = 'grand_dukes_official_birthday';
Expand Down
81 changes: 81 additions & 0 deletions src/Provider/Latvia/Latvia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/*
* This file is part of the umulmrum/holiday package.
*
* (c) Stefan Kruppa
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Umulmrum\Holiday\Provider\Latvia;

use Umulmrum\Holiday\Compensatory\CompensatoryDaysCalculator;
use Umulmrum\Holiday\Constant\HolidayName;
use Umulmrum\Holiday\Constant\HolidayType;
use Umulmrum\Holiday\Model\Holiday;
use Umulmrum\Holiday\Model\HolidayList;
use Umulmrum\Holiday\Provider\CommonHolidaysTrait;
use Umulmrum\Holiday\Provider\CompensatoryHolidayProviderInterface;
use Umulmrum\Holiday\Provider\Religion\ChristianHolidaysTrait;

use function array_filter;

class Latvia implements CompensatoryHolidayProviderInterface
{
use ChristianHolidaysTrait;
use CommonHolidaysTrait;

public function calculateHolidaysForYear(int $year): HolidayList
{
return new HolidayList(array_filter([
$this->getNewYear($year, HolidayType::DAY_OFF),
$this->getGoodFriday($year, HolidayType::OFFICIAL | HolidayType::DAY_OFF | HolidayType::PARTIAL_ONLY),
$this->getEasterMonday($year, HolidayType::OFFICIAL | HolidayType::DAY_OFF),
$this->getLaborDay($year, HolidayType::DAY_OFF),
$this->getRestorationOfIndependenceDay($year, HolidayType::DAY_OFF),
$this->getMidsummersEve($year, HolidayType::DAY_OFF),
$this->getMidsummersDay($year, HolidayType::DAY_OFF),
$this->getProclamationDay($year, HolidayType::DAY_OFF),
$this->getChristmasEve($year, HolidayType::DAY_OFF | HolidayType::PARTIAL_ONLY),
$this->getChristmasDay($year, HolidayType::OFFICIAL | HolidayType::DAY_OFF),
$this->getSecondChristmasDay($year, HolidayType::OFFICIAL | HolidayType::DAY_OFF),
$this->getNewYearsEve($year, HolidayType::OFFICIAL | HolidayType::DAY_OFF),
]));
}

protected function getRestorationOfIndependenceDay(int $year, int $additionalType = HolidayType::OTHER): ?Holiday
{
return $year >= 1990
? Holiday::create(HolidayName::RESTORATION_OF_INDEPENDENCE_DAY, "{$year}-05-04", HolidayType::OFFICIAL | $additionalType)
: null;
}

protected function getMidsummersEve(int $year, int $additionalType = HolidayType::OTHER): Holiday
{
return Holiday::create(HolidayName::MIDSUMMER_EVE, "{$year}-06-23", HolidayType::OFFICIAL | $additionalType);
}

protected function getMidsummersDay(int $year, int $additionalType = HolidayType::OTHER): Holiday
{
return Holiday::create(HolidayName::MIDSUMMERS_DAY, "{$year}-06-24", HolidayType::OFFICIAL | $additionalType);
}

protected function getProclamationDay(int $year, int $additionalType = HolidayType::OTHER): Holiday
{
return Holiday::create(HolidayName::PROCLAMATION_DAY_OF_THE_REPUBLIC_OF_LATVIA, "{$year}-11-18", HolidayType::OFFICIAL | $additionalType);
}

public function getCompensatoryDaysCalculators(int $year): array
{
return [
new CompensatoryDaysCalculator(
[
HolidayName::RESTORATION_OF_INDEPENDENCE_DAY,
HolidayName::PROCLAMATION_DAY_OF_THE_REPUBLIC_OF_LATVIA,
],
),
];
}
}
3 changes: 3 additions & 0 deletions src/Resolver/isoData.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
'IT' => \Umulmrum\Holiday\Provider\Italy\Italy::class,
'IT-32' => \Umulmrum\Holiday\Provider\Italy\SouthTyrol::class,

// Latvia
'LV' => \Umulmrum\Holiday\Provider\Latvia\Latvia::class,

// Liechtenstein
'FL' => \Umulmrum\Holiday\Provider\Liechtenstein\Liechtenstein::class,

Expand Down
52 changes: 52 additions & 0 deletions tests/Provider/Data/LV-Latvia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 1989

| Date | Name | Types |
|------------|---------------------------------------------------------|--------------------------------------------|
| 1989-01-01 | new_year | official, day_off |
| 1989-03-24 | good_friday | official, day_off, religious, partial_only |
| 1989-03-27 | easter_monday | official, day_off, religious |
| 1989-05-01 | labor_day | official, day_off |
| 1989-06-23 | midsummer_eve | official, day_off |
| 1989-06-24 | midsummers_day | official, day_off |
| 1989-11-18 | proclamation_day_of_the_republic_of_latvia | official, day_off |
| 1989-11-20 | proclamation_day_of_the_republic_of_latvia_compensatory | official, day_off, compensatory |
| 1989-12-24 | christmas_eve | day_off, religious, partial_only |
| 1989-12-25 | christmas_day | official, day_off, religious |
| 1989-12-26 | second_christmas_day | official, day_off, religious |
| 1989-12-31 | new_years_eve | official, day_off |

# 1990

| Date | Name | Types |
|------------|---------------------------------------------------------|--------------------------------------------|
| 1990-01-01 | new_year | official, day_off |
| 1990-04-13 | good_friday | official, day_off, religious, partial_only |
| 1990-04-16 | easter_monday | official, day_off, religious |
| 1990-05-01 | labor_day | official, day_off |
| 1990-05-04 | restoration_of_independence_day | official, day_off |
| 1990-06-23 | midsummer_eve | official, day_off |
| 1990-06-24 | midsummers_day | official, day_off |
| 1990-11-18 | proclamation_day_of_the_republic_of_latvia | official, day_off |
| 1990-11-19 | proclamation_day_of_the_republic_of_latvia_compensatory | official, day_off, compensatory |
| 1990-12-24 | christmas_eve | day_off, religious, partial_only |
| 1990-12-25 | christmas_day | official, day_off, religious |
| 1990-12-26 | second_christmas_day | official, day_off, religious |
| 1990-12-31 | new_years_eve | official, day_off |

# 2024

| Date | Name | Types |
|------------|----------------------------------------------|--------------------------------------------|
| 2024-01-01 | new_year | official, day_off |
| 2024-03-29 | good_friday | official, day_off, religious, partial_only |
| 2024-04-01 | easter_monday | official, day_off, religious |
| 2024-05-01 | labor_day | official, day_off |
| 2024-05-04 | restoration_of_independence_day | official, day_off |
| 2024-05-06 | restoration_of_independence_day_compensatory | official, day_off, compensatory |
| 2024-06-23 | midsummer_eve | official, day_off |
| 2024-06-24 | midsummers_day | official, day_off |
| 2024-11-18 | proclamation_day_of_the_republic_of_latvia | official, day_off |
| 2024-12-24 | christmas_eve | day_off, religious, partial_only |
| 2024-12-25 | christmas_day | official, day_off, religious |
| 2024-12-26 | second_christmas_day | official, day_off, religious |
| 2024-12-31 | new_years_eve | official, day_off |
3 changes: 2 additions & 1 deletion tests/regenerateTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tests/console test:generate CA-SK -y 1952 -y 1982 -y 1983 -y 2006 -y 2007 -y 202
tests/console test:generate CA-YT -y 1952 -y 1982 -y 1983 -y 2016 -y 2017 -y 2022 -y 2023 -y 2024
tests/console test:generate CZ -y 1950 -y 1951 -y 1987 -y 1988 -y 1989 -y 1990 -y 1991 -y 1992 -y 1999 -y 2000 -y 2015 -y 2016 -y 2024
tests/console test:generate DK -y 1848 -y 1849 -y 1891 -y 2020 -y 2024
tests/console test:generate EE -y 1997 -y 1998 -y 2024
tests/console test:generate FI -y 1950 -y 1955 -y 1991 -y 2024
tests/console test:generate FR -y 2004 -y 2019
tests/console test:generate FR-57 -y 2004 -y 2019
Expand Down Expand Up @@ -80,7 +81,7 @@ tests/console test:generate IS -y 2024 -y 2025
tests/console test:generate IE -y 1870 -y 1902 -y 1974 -y 2011 -y 2019 -y 2020
tests/console test:generate IT -y 1911 -y 1945 -y 1946 -y 1950 -y 1961 -y 1977 -y 1985 -y 2001 -y 2011 -y 2020
tests/console test:generate IT-32 -y 2020
tests/console test:generate EE -y 1997 -y 1998 -y 2024
tests/console test:generate LV -y 1989 -y 1990 -y 2024
tests/console test:generate FL -y 2020
tests/console test:generate LU -y 1961 -y 2018 -y 2020
tests/console test:generate MX -y 1825 -y 1826 -y 1911 -y 1918 -y 1923 -y 2006 -y 2010 -y 2020 -y 2021 -y 2022 -y 2021,2022
Expand Down

0 comments on commit 40b9a83

Please sign in to comment.