-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Slovenian holidays. * Created tests for Slovenian holidays.
- Loading branch information
1 parent
0844eda
commit 39deed4
Showing
3 changed files
with
93 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ composer.lock | |
/vendor/ | ||
/coverage/ | ||
/.idea/ | ||
/.vscode/ |
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,46 @@ | ||
<?php | ||
|
||
/** | ||
* Slovenian holidays. | ||
* | ||
* Days that are commented are holidays, but not work-free-days. | ||
* Source: http://www.vlada.si/o_sloveniji/politicni_sistem/prazniki/ | ||
*/ | ||
return array( | ||
'01/01', // novo leto | ||
'02/01', // novo leto | ||
'08/02', // Prešernov dan, slovenski kulturni praznik | ||
'27/04', // dan upora proti okupatorju | ||
'01/05', // praznik dela | ||
'02/05', // praznik dela | ||
// '08/06', // dan Primoža Trubarja | ||
'25/06', // dan državnosti | ||
'15/08', // Marijino vnebovzetje | ||
// '17/08', // združitev prekmurskih Slovencev z matičnim narodom | ||
// '15/09', // vrnitev Primorske k matični domovini | ||
// '25/10', // dan suverenosti | ||
'31/10', // dan reformacije | ||
'01/11', // dan spomina na mrtve | ||
// '23/11', // dan Rudolfa Maistra | ||
'25/12', // božič | ||
'26/12', // dan samostojnosti in enotnosti | ||
|
||
function ($year) { // velika noč | ||
$days = easter_days($year); | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // velikonočni ponedeljek | ||
$days = easter_days($year) + 1; | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // binkoštna nedelja - binkošti | ||
$days = easter_days($year) + 49; | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
); |
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,46 @@ | ||
<?php | ||
|
||
namespace Tests\Cmixin\Holidays; | ||
|
||
use Cmixin\BusinessDay; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SlTest extends TestCase | ||
{ | ||
const CARBON_CLASS = 'Carbon\Carbon'; | ||
|
||
protected function setUp() | ||
{ | ||
BusinessDay::enable(static::CARBON_CLASS); | ||
$carbon = static::CARBON_CLASS; | ||
$carbon::resetHolidays(); | ||
} | ||
|
||
public function testHolidays() | ||
{ | ||
$carbon = static::CARBON_CLASS; | ||
$carbon::setHolidaysRegion('sl-national'); | ||
$holidays = include __DIR__.'/../../../src/Cmixin/Holidays/sl-national.php'; | ||
|
||
$randomYear = rand(1991, 2028); | ||
$randomHolidays = array(); | ||
foreach ($holidays as $holiday) { | ||
if (is_callable($holiday)) { | ||
$randomHolidays[] = $holiday($randomYear); | ||
} elseif (is_string($holiday)) { | ||
$randomHolidays[] = $holiday; | ||
} | ||
} | ||
|
||
$date = $carbon::parse("$randomYear-01-01"); | ||
while ($date->format('Y') == $randomYear) { | ||
if (in_array($date->format('d/m'), $randomHolidays)) { | ||
self::assertTrue($date->isHoliday(), sprintf('Date %s should be holiday!', $date->format('Y-m-d'))); | ||
} else { | ||
self::assertFalse($date->isHoliday(), sprintf('Date %s should not be holiday!', $date->format('Y-m-d'))); | ||
} | ||
|
||
$date->modify('+1 day'); | ||
} | ||
} | ||
} |