Skip to content

Commit

Permalink
Merge pull request #5 from crazko/one-off-holidays
Browse files Browse the repository at this point in the history
Add one-off holidays
  • Loading branch information
ujovlado authored Sep 21, 2018
2 parents 237642e + 0ca26b2 commit 13927b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Rekurzia/SlovakHolidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class SlovakHolidays
'monday' => 'Veľkonočný pondelok'
];

/** @var array */
private static $oneOffHolidays = [
'2018-10-30' => '100. výročie prijatia Deklarácie slovenského národa'
];

/**
* Constructor to disable instantiation
* @throws SlovakHolidaysException
Expand Down Expand Up @@ -67,6 +72,14 @@ public static function getHolidays($year = null, $month = null)
$holidays[$year . '-' . $key] = $holiday;
}

foreach (self::$oneOffHolidays as $key => $holiday) {
$date = date_parse($key);

if ($date['year'] === $year) {
$holidays[$key] = $holiday;
}
}

ksort($holidays);

if ($month !== null) {
Expand Down
21 changes: 21 additions & 0 deletions tests/SlovakHolidays.test.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ require __DIR__ . '/bootstrap.php';
use Tester\Assert;
use Rekurzia\SlovakHolidays;

Assert::same(true, SlovakHolidays::isDayHoliday(2018, 10, 30));
Assert::same(false, SlovakHolidays::isDayHoliday(2017, 10, 30));
Assert::same([
'2018-01-01',
'2018-01-06',
'2018-03-30',
'2018-04-02',
'2018-05-01',
'2018-05-08',
'2018-07-05',
'2018-08-29',
'2018-09-01',
'2018-09-15',
'2018-10-30',
'2018-11-01',
'2018-11-17',
'2018-12-24',
'2018-12-25',
'2018-12-26',
], array_keys(SlovakHolidays::getHolidays(2018)));

Assert::exception(function() {
new SlovakHolidays;
}, 'Rekurzia\SlovakHolidaysException', 'Class cannot be instantiated');
Expand Down

0 comments on commit 13927b8

Please sign in to comment.