Skip to content

Commit

Permalink
Add Romanian Holidays (#27)
Browse files Browse the repository at this point in the history
* add romanian holidays

* add Epiphany and Saint John public holidays

* fix static analysis

* Fix styling

* add formula to calculate the difference between Julian and Gregorian calendars

* Fix styling

* add the source of the orthodox easter algorithm

* Fix styling

* fix phpstan

* remove orthodoxEaster function from Romania class
  • Loading branch information
florinp authored Jan 23, 2024
1 parent 1d6960e commit 55f455f
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/Countries/Romania.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Romania extends Country
{
public function countryCode(): string
{
return 'ro';
}

/** @return array<string, string|CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
'Anul Nou' => '01-01',
'A doua zi de Anul Nou' => '01-02',
'Bobotează' => '01-06',
'Sfântul Ion' => '01-07',
'Ziua Unirii Principatelor Române' => '01-24',
'Ziua Muncii' => '05-01',
'Ziua Copilului' => '06-01',
'Adormirea Maicii Domnului' => '08-15',
'Sfântul Andrei' => '11-30',
'Ziua Națională' => '12-01',
'Crăciunul' => '12-25',
'A doua zi de Crăciun' => '12-26',
], $this->variableHolidays($year));
}

/**
* @return array<string, CarbonImmutable>
*/
protected function variableHolidays(int $year): array
{
$easter = $this->orthodoxEaster($year);
$easterMonday = $easter->addDay();
$goodFriday = $easter->subDays(2);

$pentecost = $this->orthodoxPentecost($year);
$pentecostMonday = $pentecost->addDay();

return [
'Vinerea Mare' => $goodFriday,
'Paștele' => $easter,
'A doua zi de Paște' => $easterMonday,
'Rusaliile' => $pentecost,
'A doua zi de Rusalii' => $pentecostMonday,
];
}

protected function orthodoxPentecost(int $year): CarbonImmutable
{
$easter = $this->orthodoxEaster($year);

return $easter->addDays(49);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[
{
"name": "Anul Nou",
"date": "2024-01-01"
},
{
"name": "A doua zi de Anul Nou",
"date": "2024-01-02"
},
{
"name": "Boboteaz\u0103",
"date": "2024-01-06"
},
{
"name": "Sf\u00e2ntul Ion",
"date": "2024-01-07"
},
{
"name": "Ziua Unirii Principatelor Rom\u00e2ne",
"date": "2024-01-24"
},
{
"name": "Ziua Muncii",
"date": "2024-05-01"
},
{
"name": "Vinerea Mare",
"date": "2024-05-03"
},
{
"name": "Pa\u0219tele",
"date": "2024-05-05"
},
{
"name": "A doua zi de Pa\u0219te",
"date": "2024-05-06"
},
{
"name": "Ziua Copilului",
"date": "2024-06-01"
},
{
"name": "Rusaliile",
"date": "2024-06-23"
},
{
"name": "A doua zi de Rusalii",
"date": "2024-06-24"
},
{
"name": "Adormirea Maicii Domnului",
"date": "2024-08-15"
},
{
"name": "Sf\u00e2ntul Andrei",
"date": "2024-11-30"
},
{
"name": "Ziua Na\u021bional\u0103",
"date": "2024-12-01"
},
{
"name": "Cr\u0103ciunul",
"date": "2024-12-25"
},
{
"name": "A doua zi de Cr\u0103ciun",
"date": "2024-12-26"
}
]
19 changes: 19 additions & 0 deletions tests/Countries/RomaniaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate romanian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'ro')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();

});

0 comments on commit 55f455f

Please sign in to comment.