Skip to content

Commit

Permalink
Slovenian holidays (#3)
Browse files Browse the repository at this point in the history
* Added Slovenian holidays.
* Created tests for Slovenian holidays.
  • Loading branch information
Glavic authored and kylekatarnls committed May 17, 2018
1 parent 0844eda commit 39deed4
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ composer.lock
/vendor/
/coverage/
/.idea/
/.vscode/
46 changes: 46 additions & 0 deletions src/Cmixin/Holidays/sl-national.php
@@ -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');
},
);
46 changes: 46 additions & 0 deletions tests/Cmixin/Holidays/SlTest.php
@@ -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');
}
}
}

0 comments on commit 39deed4

Please sign in to comment.