Skip to content

Commit

Permalink
Add more tests and translation for Bosnia and Herzegovina
Browse files Browse the repository at this point in the history
  • Loading branch information
DesaBL committed Mar 7, 2024
1 parent 816005b commit a0f8a67
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 23 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"
}
50 changes: 27 additions & 23 deletions src/Countries/BosniaAndHerzegovina.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
namespace Spatie\Holidays\Countries;

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

class BosniaAndHerzegovina extends Country
{
protected function __construct(
protected ?string $region = null,
) {
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
Expand All @@ -33,31 +42,26 @@ protected function allHolidays(int $year): array
/** @return array<string, string> */
protected function regionHolidays(): array
{
switch ($this->region) {
case 'BA-RS':
return [
'Dan Republike' => '01-09',
'Dan pobjede nad fašizmom' => '05-09',
'Dan uspostavljanja Opšteg okvirnog sporazuma za mir u BiH' => '11-21',
];
case 'BA-FBIH':
return [
'Dan nezavisnosti Bosne i Hercegovine' => '03-01',
'Dan državnosti Bosne i Hercegovine' => '11-25',
];
case 'BA-BD':
return [
'Dan uspostavljanja Brčko distrikta' => '03-08',
];
}

return [];
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
{
// Orthodox Easter calculation needs to be in the same timezone as the country
$orthodoxEaster = $this->orthodoxEaster($year);
$orthodoxGoodFriday = $orthodoxEaster->copy()->subDays(2);
$orthodoxEasterMonday = $orthodoxEaster->copy()->addDay();
Expand Down
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"
}
]
29 changes: 29 additions & 0 deletions tests/Countries/BosniaAndHerzegovinaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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 () {
Expand All @@ -16,3 +18,30 @@

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 a0f8a67

Please sign in to comment.