Skip to content

Commit

Permalink
Add holidays for Bosnia And Herzegovina (#203)
Browse files Browse the repository at this point in the history
* Add holidays for Bosnia And Herzegovina

* Add more tests and translation for Bosnia and Herzegovina
  • Loading branch information
DesaBL authored Mar 22, 2024
1 parent e0cf796 commit 6ce8f02
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lang/bosniaAndHerzegovina/en/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Nova godina - prvi dan": "New Year - first day",
"Nova godina - drugi dan": "New Year - second day",
"Badnji dan (za pravoslavce)": "Christmas Eve (Orthodox)",
"Božić (za pravoslavce)": "Christmas (Orthodox)",
"Badnji dan (za rimokatolike)": "Christmas Eve (Catholic)",
"Božić (za rimokatolike)": "Christmas (Catholic)",
"Praznik rada - prvi dan": "Labour Day - first day",
"Praznik rada - drugi dan": "Labour Day - second day",
"Veliki petak (za pravoslavce)": "Good Friday (Orthodox)",
"Veliki petak (za rimokatolike)": "Good Friday (Catholic)",
"Vaskrs (za pravoslavce)": "Easter (Orthodox)",
"Vaskrs (za rimokatolike)": "Easter (Catholic)",
"Vaskršnji ponedjeljak (za pravoslavce)": "Easter Monday (Orthodox)",
"Vaskršnji ponedjeljak (za rimokatolike)": "Easter Monday (Catholic)",

"Dan Republike": "Republic Day",
"Dan pobjede nad fašizmom": "The day of victory over fascism",
"Dan uspostavljanja Opšteg okvirnog sporazuma za mir u BiH": "The day of establishment of the General Framework Agreement for Peace in Bosnia and Herzegovina",

"Dan nezavisnosti Bosne i Hercegovine": "Independence Day of Bosnia And Herzegovina",
"Dan državnosti Bosne i Hercegovine": "National Day of Bosnia And Herzegovina",

"Dan uspostavljanja Brčko distrikta": "Day of establishment of Brčko District"
}
87 changes: 87 additions & 0 deletions src/Countries/BosniaAndHerzegovina.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Exceptions\InvalidRegion;

class BosniaAndHerzegovina extends Country
{
private const REGIONS = [
'ba-rs',
'ba-fbih',
'ba-bd',
];

public function __construct(protected ?string $region = null)
{
if ($region !== null && ! in_array($region, self::REGIONS)) {
throw InvalidRegion::notFound($region);
}
}

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

protected function allHolidays(int $year): array
{
return array_merge([
'Nova godina - prvi dan' => '01-01',
'Nova godina - drugi dan' => '01-02',
'Badnji dan (za pravoslavce)' => '01-06',
'Božić (za pravoslavce)' => '01-07',
'Praznik rada - prvi dan' => '05-01',
'Praznik rada - drugi dan' => '05-02',
'Badnji dan (za rimokatolike)' => '12-24',
'Božić (za rimokatolike)' => '12-25',
], $this->regionHolidays());
}

/** @return array<string, string> */
protected function regionHolidays(): array
{
return match ($this->region) {
'ba-rs' => [
'Dan Republike' => '01-09',
'Dan pobjede nad fašizmom' => '05-09',
'Dan uspostavljanja Opšteg okvirnog sporazuma za mir u BiH' => '11-21',
],
'ba-fbih' => [
'Dan nezavisnosti Bosne i Hercegovine' => '03-01',
'Dan državnosti Bosne i Hercegovine' => '11-25',
],
'ba-bd' => [
'Dan uspostavljanja Brčko distrikta' => '03-08',
],
default => [],
};
}

/** @return array<string, CarbonImmutable> */
public function variableHolidays(int $year): array
{
$orthodoxEaster = $this->orthodoxEaster($year);
$orthodoxGoodFriday = $orthodoxEaster->copy()->subDays(2);
$orthodoxEasterMonday = $orthodoxEaster->copy()->addDay();

$easter = $this->easter($year);
$goodFriday = $easter->copy()->subDays(2);
$easterMonday = $easter->copy()->addDay();

// TODO: Implement islamic holidays

return [
// Orthodox holidays
'Vaskrs (za pravoslavce)' => $orthodoxEaster,
'Vaskršnji ponedjeljak (za pravoslavce)' => $orthodoxEasterMonday,
'Veliki petak (za pravoslavce)' => $orthodoxGoodFriday,

// Catholic holidays
'Vaskrs (za rimokatolike)' => $easter,
'Vaskršnji ponedjeljak (za rimokatolike)' => $easterMonday,
'Veliki petak (za rimokatolike)' => $goodFriday,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"name": "Nova godina - prvi dan",
"date": "2024-01-01"
},
{
"name": "Nova godina - drugi dan",
"date": "2024-01-02"
},
{
"name": "Badnji dan (za pravoslavce)",
"date": "2024-01-06"
},
{
"name": "Bo\u017ei\u0107 (za pravoslavce)",
"date": "2024-01-07"
},
{
"name": "Praznik rada - prvi dan",
"date": "2024-05-01"
},
{
"name": "Praznik rada - drugi dan",
"date": "2024-05-02"
},
{
"name": "Badnji dan (za rimokatolike)",
"date": "2024-12-24"
},
{
"name": "Bo\u017ei\u0107 (za rimokatolike)",
"date": "2024-12-25"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"name": "Nova godina - prvi dan",
"date": "2024-01-01"
},
{
"name": "Nova godina - drugi dan",
"date": "2024-01-02"
},
{
"name": "Badnji dan (za pravoslavce)",
"date": "2024-01-06"
},
{
"name": "Bo\u017ei\u0107 (za pravoslavce)",
"date": "2024-01-07"
},
{
"name": "Praznik rada - prvi dan",
"date": "2024-05-01"
},
{
"name": "Praznik rada - drugi dan",
"date": "2024-05-02"
},
{
"name": "Badnji dan (za rimokatolike)",
"date": "2024-12-24"
},
{
"name": "Bo\u017ei\u0107 (za rimokatolike)",
"date": "2024-12-25"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"name": "New Year - first day",
"date": "2024-01-01"
},
{
"name": "New Year - second day",
"date": "2024-01-02"
},
{
"name": "Christmas Eve (Orthodox)",
"date": "2024-01-06"
},
{
"name": "Christmas (Orthodox)",
"date": "2024-01-07"
},
{
"name": "Labour Day - first day",
"date": "2024-05-01"
},
{
"name": "Labour Day - second day",
"date": "2024-05-02"
},
{
"name": "Christmas Eve (Catholic)",
"date": "2024-12-24"
},
{
"name": "Christmas (Catholic)",
"date": "2024-12-25"
}
]
47 changes: 47 additions & 0 deletions tests/Countries/BosniaAndHerzegovinaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Countries\BosniaAndHerzegovina;
use Spatie\Holidays\Exceptions\InvalidRegion;
use Spatie\Holidays\Holidays;

it('can calculate bosnia and herzegovina holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

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

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

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

it('throws an error when an invalid region is given', function () {
new BosniaAndHerzegovina('ba-xy');
})->throws(InvalidRegion::class);

it('can calculate victory day for republic of srpska in bosnia and herzegovina holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

$victoryDay = Holidays::for(BosniaAndHerzegovina::make())->isHoliday('2024-01-09');
expect($victoryDay)->toBeFalse();

$victoryDayForRepublicOfSprska = Holidays::for(BosniaAndHerzegovina::make('ba-rs'))->isHoliday('2024-01-09');
expect($victoryDayForRepublicOfSprska)->toBeTrue();
});

it('can translate holidays into english', function () {
$holidays = Holidays::for(country: 'ba', locale: 'en', year: 2024)->get();

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

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

expect($holidays[0]['name'])->toBe('New Year - first day');
});

0 comments on commit 6ce8f02

Please sign in to comment.