-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6886d26
commit 3454833
Showing
2 changed files
with
168 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,52 @@ | ||
<?php | ||
|
||
return array( | ||
'01/01', // Nieuwjaarsdag | ||
function ($year) { // Paaszondag | ||
$days = easter_days($year); | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // Paasmaandag | ||
$days = easter_days($year) + 1; | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // Koningsdag | ||
$date = new DateTime("$year-04-27"); | ||
if ($date->format('w') === '0') { | ||
$date->sub(new DateInterval('P1D')); | ||
} | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // Bevrijdingsdag | ||
if ($year % 5 === 0) { | ||
$date = new DateTime("$year-05-05"); | ||
|
||
return $date->format('d/m'); | ||
} | ||
}, | ||
function ($year) { // Hemelvaart | ||
$days = easter_days($year) + 39; | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // Pinksterzondag | ||
$days = easter_days($year) + 49; | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
function ($year) { // Pinkstermaandag | ||
$days = easter_days($year) + 50; | ||
$date = new DateTime("$year-03-21 +$days days"); | ||
|
||
return $date->format('d/m'); | ||
}, | ||
'25/12', // Eerste Kerstdag | ||
'26/12', // Tweede Kerstdag | ||
); |
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,116 @@ | ||
<?php | ||
/** | ||
* Author: Herman Slatman | ||
* Date: 20/10/2018 | ||
* Time: 00:11. | ||
*/ | ||
|
||
namespace Tests\Cmixin\Holidays; | ||
|
||
use Cmixin\BusinessDay; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NlTest extends TestCase | ||
{ | ||
const CARBON_CLASS = 'Carbon\Carbon'; | ||
|
||
protected function setUp() | ||
{ | ||
BusinessDay::enable(static::CARBON_CLASS); | ||
$carbon = static::CARBON_CLASS; | ||
$carbon::resetHolidays(); | ||
} | ||
|
||
public function testHolidaysForRandomYear() | ||
{ | ||
$carbon = static::CARBON_CLASS; | ||
$carbon::setHolidaysRegion('nl-national'); | ||
$holidays = include __DIR__.'/../../../src/Cmixin/Holidays/nl-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'); | ||
} | ||
} | ||
|
||
public function testHolidaysSpecificDates() | ||
{ | ||
$carbon = static::CARBON_CLASS; | ||
$carbon::setHolidaysRegion('nl-national'); | ||
|
||
self::assertTrue($carbon::parse('2000-01-01 00:00:00')->isHoliday()); | ||
self::assertTrue($carbon::parse('2018-04-27')->isHoliday()); | ||
self::assertFalse($carbon::parse('2018-04-26')->isHoliday()); | ||
self::assertTrue($carbon::parse('2018-04-01')->isHoliday()); | ||
self::assertTrue($carbon::parse('2018-04-02')->isHoliday()); | ||
self::assertFalse($carbon::parse('2018-05-05')->isHoliday()); // Liberation Day; only once every 5 years | ||
self::assertTrue($carbon::parse('2020-05-05')->isHoliday()); | ||
self::assertTrue($carbon::parse('2018-05-10')->isHoliday()); | ||
self::assertTrue($carbon::parse('2018-05-20')->isHoliday()); | ||
self::assertTrue($carbon::parse('2018-05-21')->isHoliday()); | ||
self::assertTrue($carbon::parse('2000-12-25 00:00:00')->isHoliday()); | ||
self::assertTrue($carbon::parse('2000-12-26 00:00:00')->isHoliday()); | ||
|
||
self::assertTrue($carbon::parse('2019-04-21')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-04-22')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-04-12')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-04-13')->isHoliday()); | ||
self::assertTrue($carbon::parse('2021-04-04')->isHoliday()); | ||
self::assertTrue($carbon::parse('2021-04-05')->isHoliday()); | ||
self::assertTrue($carbon::parse('2022-04-17')->isHoliday()); | ||
self::assertTrue($carbon::parse('2022-04-18')->isHoliday()); | ||
self::assertTrue($carbon::parse('2023-04-09')->isHoliday()); | ||
self::assertTrue($carbon::parse('2023-04-10')->isHoliday()); | ||
self::assertTrue($carbon::parse('2024-03-31')->isHoliday()); | ||
self::assertTrue($carbon::parse('2024-04-01')->isHoliday()); | ||
self::assertTrue($carbon::parse('2025-04-20')->isHoliday()); | ||
self::assertTrue($carbon::parse('2025-04-21')->isHoliday()); | ||
self::assertTrue($carbon::parse('2026-04-05')->isHoliday()); | ||
self::assertTrue($carbon::parse('2026-04-06')->isHoliday()); | ||
self::assertTrue($carbon::parse('2027-03-28')->isHoliday()); | ||
self::assertTrue($carbon::parse('2027-03-29')->isHoliday()); | ||
self::assertTrue($carbon::parse('2028-04-16')->isHoliday()); | ||
self::assertTrue($carbon::parse('2028-04-17')->isHoliday()); | ||
self::assertTrue($carbon::parse('2029-04-01')->isHoliday()); | ||
self::assertTrue($carbon::parse('2029-04-02')->isHoliday()); | ||
|
||
self::assertTrue($carbon::parse('2019-01-01 00:00:00')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-04-21')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-04-22')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-04-27')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-05-30')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-06-09')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-06-10')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-12-25 00:00:00')->isHoliday()); | ||
self::assertTrue($carbon::parse('2019-12-26 00:00:00')->isHoliday()); | ||
|
||
self::assertTrue($carbon::parse('2020-01-01 00:00:00')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-04-12')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-04-13')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-04-27')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-05-05')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-05-21')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-05-31')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-06-01')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-12-25 00:00:00')->isHoliday()); | ||
self::assertTrue($carbon::parse('2020-12-26 00:00:00')->isHoliday()); | ||
|
||
self::assertTrue($carbon::parse('2025-04-26')->isHoliday()); // Kingsday on Sunday :-> Saturday | ||
} | ||
} |