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

Add Greece holidays #114

Merged
merged 16 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
81 changes: 81 additions & 0 deletions src/Countries/Greece.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Greece extends Country
{
public function countryCode(): string
{
return 'el';
}

/** @return array<string, string|CarbonImmutable> */
lowv-developer marked this conversation as resolved.
Show resolved Hide resolved
protected function allHolidays(int $year): array
{
return array_merge([
'Πρωτοχρονιά' => '01-01',
'Θεοφάνια' => '01-06',
'25η Μαρτίου' => '03-25',
'Πρωτομαγιά' => '05-01',
'Δεκαπενταύγουστος' => '08-15',
'28η Οκτωβρίου' => '10-28',
'Χριστούγεννα' => '12-25',
'Σύναξη της Θεοτόκου' => '12-26',

], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{

$orthodox_easter = CarbonImmutable::createFromTimestamp(
$this->calculateOrthodoxEaster($year)
lowv-developer marked this conversation as resolved.
Show resolved Hide resolved
)->setTimezone("Europe/Athens");


$protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01");

if (
$protomagia == $orthodox_easter->subDays(2) ||
$protomagia == $orthodox_easter->subDays(1) ||
$protomagia == $orthodox_easter ||
$protomagia == $orthodox_easter->addDay()
) {
$protomagia = $orthodox_easter->addDays(2);
}
if ($protomagia->isSunday()) {

Check failure on line 49 in src/Countries/Greece.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method isSunday() on Carbon\CarbonImmutable|false.
$protomagia = $protomagia->addDay();

Check failure on line 50 in src/Countries/Greece.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method addDay() on Carbon\CarbonImmutable|false.
}

return [

Check failure on line 53 in src/Countries/Greece.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Greece::variableHolidays() should return array<string, Carbon\CarbonImmutable> but returns array<string, Carbon\CarbonImmutable|false>.
'Καθαρά Δευτέρα' => $orthodox_easter->subDays(48), //always Monday
'Πρωτομαγιά' => $protomagia,
'Μεγάλη Παρασκευή' => $orthodox_easter->subDays(2),
'Κυριακή του Πάσχα' => $orthodox_easter,
'Δευτέρα του Πάσχα' => $orthodox_easter->addDay(),
'Αγίου Πνεύματος' => $orthodox_easter->addDays(50), //always Monday
];
}

/** @return integer */
protected function calculateOrthodoxEaster(int $year): int
{
$a = $year % 4;
$b = $year % 7;
$c = $year % 19;
$d = (19 * $c + 15) % 30;
$e = (2 * $a + 4 * $b - $d + 34) % 7;
$month = (int) (($d + $e + 114) / 31);
$day = (($d + $e + 114) % 31) + 1;
// julian to gregorian
$jtg = (int) ($year / 100) - (int) ($year / 400) - 2;

$easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year);

return (int) $easterDate;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"name": "\u03a0\u03c1\u03c9\u03c4\u03bf\u03c7\u03c1\u03bf\u03bd\u03b9\u03ac",
"date": "2024-01-01"
},
{
"name": "\u0398\u03b5\u03bf\u03c6\u03ac\u03bd\u03b9\u03b1",
"date": "2024-01-06"
},
{
"name": "\u039a\u03b1\u03b8\u03b1\u03c1\u03ac \u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1",
"date": "2024-03-18"
},
{
"name": "25\u03b7 \u039c\u03b1\u03c1\u03c4\u03af\u03bf\u03c5",
"date": "2024-03-25"
},
{
"name": "\u03a0\u03c1\u03c9\u03c4\u03bf\u03bc\u03b1\u03b3\u03b9\u03ac",
"date": "2024-05-01"
},
{
"name": "\u039c\u03b5\u03b3\u03ac\u03bb\u03b7 \u03a0\u03b1\u03c1\u03b1\u03c3\u03ba\u03b5\u03c5\u03ae",
"date": "2024-05-03"
},
{
"name": "\u039a\u03c5\u03c1\u03b9\u03b1\u03ba\u03ae \u03c4\u03bf\u03c5 \u03a0\u03ac\u03c3\u03c7\u03b1",
"date": "2024-05-05"
},
{
"name": "\u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1 \u03c4\u03bf\u03c5 \u03a0\u03ac\u03c3\u03c7\u03b1",
"date": "2024-05-06"
},
{
"name": "\u0391\u03b3\u03af\u03bf\u03c5 \u03a0\u03bd\u03b5\u03cd\u03bc\u03b1\u03c4\u03bf\u03c2",
"date": "2024-06-24"
},
{
"name": "\u0394\u03b5\u03ba\u03b1\u03c0\u03b5\u03bd\u03c4\u03b1\u03cd\u03b3\u03bf\u03c5\u03c3\u03c4\u03bf\u03c2",
"date": "2024-08-15"
},
{
"name": "28\u03b7 \u039f\u03ba\u03c4\u03c9\u03b2\u03c1\u03af\u03bf\u03c5",
"date": "2024-10-28"
},
{
"name": "\u03a7\u03c1\u03b9\u03c3\u03c4\u03bf\u03cd\u03b3\u03b5\u03bd\u03bd\u03b1",
"date": "2024-12-25"
},
{
"name": "\u03a3\u03cd\u03bd\u03b1\u03be\u03b7 \u03c4\u03b7\u03c2 \u0398\u03b5\u03bf\u03c4\u03cc\u03ba\u03bf\u03c5",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/GreeceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

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

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

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

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

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