1. Go to this page and download the library: Download niirrty/niirrty.holiday library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
niirrty / niirrty.holiday example snippets
use Niirrty\Holiday\CountryDefinitionsFactory;
// Load the country depending ('de' == 'Germany') holiday definitions
$holidayDefinitions = CountryDefinitionsFactory::Create( 'de' );
// Get the german holidays for year 2018 in english language
$holidays = $holidayDefinitions->getHolidays( 2018, 'en' );
// Sort holidays by date
$holidays->sort();
// Output small info about the holidays
foreach ( $holidays as $holiday )
{
echo $holiday->getDate()->format( 'Y-m-d' ), ' : ', $holiday->getName(), "\n";
}
use Niirrty\Holiday\CountryDefinitionsFactory;
$supportedCountries = CountryDefinitionsFactory::GetSupportedCountries();
$holidayDefinitions->getRegions();
use Niirrty\Holiday\Definition;
use Niirrty\Holiday\DefinitionCollection;
use Niirrty\Holiday\Identifiers;
return DefinitionCollection::Create( 'United Kingdom', 'uk' )
->setRegions(
[
// TODO 1: If xes.
'Alderney', // 0
'England', // 1
'Guernsey', // 2
'Isle of Man', // 3
'Jersey', // 4
'North Ireland', // 5
'Scotland', // 6
'Wales' // 7
] )
->addRange(
// TODO 2: Here all holidays must be defined comma separated
);
// 03-17 : Saint Patrick's Day…
Definition::Create( 'Saint Patrick\'s Day' )
->setStaticDate( 3, 17 )
// move to next day (monday) if date is a sunday
->addMoveCondition( MoveCondition::OnSunday( 1 ) )
// move 2 days in future (monday) if date is a saturday
->addMoveCondition( MoveCondition::OnSaturday( 2 ) )
)
// 03-17 : Saint Patrick's Day…
Definition::Create( 'Saint Patrick\'s Day' )
->setStaticDate( 3, 17 )
// move to next day (monday) if date is a sunday
->addMoveCondition( MoveCondition::Create(
1,
function ( \DateTime $date ) : bool
{
return 0 === ( (int) $date->format( 'w' ) );
} ) )
// move 2 days in future (monday) if date is a saturday
->addMoveCondition( MoveCondition::Create(
1,
function ( \DateTime $date ) : bool
{
return 6 === ( (int) $date->format( 'w' ) );
} ) )
)
// 03-17 : Saint Patrick's Day…
Definition::Create( 'Saint Patrick\'s Day' )
->setStaticDate( 3, 17 )
// Holiday is valid for regions England (1) and Wales (7)
->setValidRegions( [ 1, 7 ] )
// Early May Bank Holiday - The 1st monday in may
Definition::Create( 'Early May Bank Holiday' )
->setDynamicDateCallback(
new \Niirrty\Holiday\Callbacks\NamedDateCallback( 'first monday of may ' ) )
)
declare( strict_types = 1 );
namespace My\Callbacks;
use Niirrty\Holiday\Callbacks\IDynamicDateCallback;
use Niirrty\Date\DateTime;
class MyDynamicDateCallback implements IDynamicDateCallback
{
public function calculate( int $year ) : \DateTime
{
return ( 0 === $year % 2 )
? DateTime::Create( $year, 5, 1 )
: DateTime::Create( $year, 5, 2 );
}
}