h4kuna/workdays

v0.3.0 2023-09-30 21:33 UTC

This package is auto-updated.

Last update: 2024-10-30 02:16:26 UTC


README

Downloads this Month Latest Stable Version Coverage Status Total Downloads License

Usage

use h4kuna\Workdays;
$builder = Workdays\Factory::create();

$workdays = $builder->get('cs_CZ');

$datetime = new DateTime('2016-01-04 12:46:28');

echo ($workdays->isHoliday($datetime) ? 'true' : 'false') . PHP_EOL;
// false

echo ($workdays->isWorkday($datetime) ? 'true' : 'false') . PHP_EOL;
// true

$nextHoliday = $workdays->nextHoliday($datetime);
echo $nextHoliday->name . PHP_EOL;
// Velký pátek
echo $nextHoliday->date->format('Y-m-d H:i:s') . PHP_EOL;
// 2016-03-25 00:00:00

echo $workdays->nextWorkday($datetime)->format('Y-m-d H:i:s') . PHP_EOL;
// 2016-01-05 12:46:28

$workdays->moveWorkdays($datetime, 7);
echo $datetime->format('Y-m-d H:i:s') . PHP_EOL;
// 2016-01-13 12:46:28


$workdays = $builder->get('sk_SK');
$datetime = new DateTime('2016-01-04 12:43:28');

echo ($workdays->isHoliday($datetime) ? 'true' : 'false') . PHP_EOL;
// false

echo ($workdays->isWorkday($datetime) ? 'true' : 'false') . PHP_EOL;
// true

$nextHoliday = $workdays->nextHoliday($datetime);
echo $nextHoliday->name . PHP_EOL;
// Zjavenie Pána
echo $nextHoliday->date->format('Y-m-d H:i:s') . PHP_EOL;
// 2016-01-06 00:00:00

echo $workdays->nextWorkday($datetime)->format('Y-m-d H:i:s') . PHP_EOL;
// 2016-01-05 12:43:28

$workdays->moveWorkdays($datetime, 7);
echo $datetime->format('Y-m-d H:i:s') . PHP_EOL;
// 2016-01-14 12:43:28

Custom Holiday Providers

use h4kuna\Workdays;

$builder = Workdays\Factory::create();

class CustomHolidaysProvider implements Workdays\HolidaysProvider\BaseProvider
{
    protected function holidaysInYear(int $year): array {
        return [
            // fill dates        
        ];
    }
}

$builder->addProvider('myProvider', new CustomHolidaysProvider());

// initialize workdays util without country code; the correct holidays provider is not yet available
$workdays = $builder->get('myProvider');