Skip to content

Commit

Permalink
Merge pull request #119 from object505/main
Browse files Browse the repository at this point in the history
Add Macedonian holidays
  • Loading branch information
freekmurze authored Jan 19, 2024
2 parents bb5af77 + b56fa3f commit 3908fc4
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Countries/NorthMacedonia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class NorthMacedonia extends Country
{

public function countryCode(): string
{
return 'mk';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Нова година' => '01-01',
'Божик, првиот ден на Божик според православниот календар' => '01-07',
'Ден на трудот' => '05-01',
'Св. Кирил и Методиј - Ден на сесловенските просветители' => '05-24',
'Ден на Републиката' => '08-02',
'Ден на независноста' => '09-08',
'Ден на народното востание' => '10-11',
'Ден на македонската револуционерна борба' => '10-23',
'Св. Климент Охридски' => '12-08',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp($this->ortodoxEaster($year))
->setTimezone('Europe/Skopje');

return [
'Велигден, вториот ден на Велигден според православниот календар' => $easter->addDay(),
];
}

protected function ortodoxEaster(int $year): bool|int
{
$timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN);
$daysDifference = (int)($year / 100) - (int)($year / 400) - 2;

return strtotime("+$daysDifference days", $timestamp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "\u041d\u043e\u0432\u0430 \u0433\u043e\u0434\u0438\u043d\u0430",
"date": "2024-01-01"
},
{
"name": "\u0411\u043e\u0436\u0438\u043a, \u043f\u0440\u0432\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0411\u043e\u0436\u0438\u043a \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440",
"date": "2024-01-07"
},
{
"name": "\u0414\u0435\u043d \u043d\u0430 \u0442\u0440\u0443\u0434\u043e\u0442",
"date": "2024-05-01"
},
{
"name": "\u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d, \u0432\u0442\u043e\u0440\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440",
"date": "2024-05-06"
},
{
"name": "\u0421\u0432. \u041a\u0438\u0440\u0438\u043b \u0438 \u041c\u0435\u0442\u043e\u0434\u0438\u0458 - \u0414\u0435\u043d \u043d\u0430 \u0441\u0435\u0441\u043b\u043e\u0432\u0435\u043d\u0441\u043a\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0432\u0435\u0442\u0438\u0442\u0435\u043b\u0438",
"date": "2024-05-24"
},
{
"name": "\u0414\u0435\u043d \u043d\u0430 \u0420\u0435\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430",
"date": "2024-08-02"
},
{
"name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u043d\u043e\u0441\u0442\u0430",
"date": "2024-09-08"
},
{
"name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0430\u0440\u043e\u0434\u043d\u043e\u0442\u043e \u0432\u043e\u0441\u0442\u0430\u043d\u0438\u0435",
"date": "2024-10-11"
},
{
"name": "\u0414\u0435\u043d \u043d\u0430 \u043c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0430\u0442\u0430 \u0440\u0435\u0432\u043e\u043b\u0443\u0446\u0438\u043e\u043d\u0435\u0440\u043d\u0430 \u0431\u043e\u0440\u0431\u0430",
"date": "2024-10-23"
},
{
"name": "\u0421\u0432. \u041a\u043b\u0438\u043c\u0435\u043d\u0442 \u041e\u0445\u0440\u0438\u0434\u0441\u043a\u0438",
"date": "2024-12-08"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/NorthMacedoniaTest.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 macedonian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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

0 comments on commit 3908fc4

Please sign in to comment.