generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add holidays for Bosnia And Herzegovina (#203)
* Add holidays for Bosnia And Herzegovina * Add more tests and translation for Bosnia and Herzegovina
- Loading branch information
Showing
6 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...Countries/BosniaAndHerzegovinaTest/it_can_calculate__bosnia_and_herzegovina_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
34 changes: 34 additions & 0 deletions
34
.../Countries/BosniaAndHerzegovinaTest/it_can_calculate_bosnia_and_herzegovina_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
34 changes: 34 additions & 0 deletions
34
.../snapshots/Countries/BosniaAndHerzegovinaTest/it_can_translate_holidays_into_english.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |