h4kuna / workdays
Fund package maintenance!
h4kuna
revolut.me/milan2m/czk1000/library
Requires
- php: >= 8.0
- h4kuna/data-type: ^3.0.5
Requires (Dev)
- nette/tester: ^2.4
- phpstan/phpstan: ^1.8
- phpstan/phpstan-deprecation-rules: ^1.1.3
- phpstan/phpstan-strict-rules: ^1.4
- tracy/tracy: ^2.9
This package is auto-updated.
Last update: 2024-09-30 01:46:49 UTC
README
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');