PHP code example of omegacode / german-workday-calculator
1. Go to this page and download the library: Download omegacode/german-workday-calculator 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/ */
omegacode / german-workday-calculator example snippets
reate an instance of the calculator and set the states for german holidays to Hessen.
$calculator = new \OmegaCode\GermanWorkdayCalculator\WorkdayCalculator();
$calculator->setState(OmegaCode\GermanWorkdayCalculator\States::NATIONAL); // Check the info section for all possibilities.
// Create some test date time objects.
$testDate = \DateTime::createFromFormat('Y-m-d', '2018-05-07');
$testDateFrom = \DateTime::createFromFormat('Y-m-d', '2018-07-03');
$testDateTill = \DateTime::createFromFormat('Y-m-d', '2018-07-10');
try {
$result1 = $calculator->calculateIncrementedDate(
$testDate,
365,
[
\OmegaCode\GermanWorkdayCalculator\WorkdayCalculator::IGNORE_SUNDAY,
\OmegaCode\GermanWorkdayCalculator\WorkdayCalculator::IGNORE_SATURDAY,
]
);
} catch (Exception $e) {
echo '[ERROR]: '.$e->getMessage().PHP_EOL;
}
try {
$result2 = $calculator->calculateByDateRange(
$testDateFrom,
$testDateTill,
[
\OmegaCode\GermanWorkdayCalculator\WorkdayCalculator::IGNORE_SUNDAY,
\OmegaCode\GermanWorkdayCalculator\WorkdayCalculator::IGNORE_SATURDAY,
]
);
} catch (OmegaCode\GermanWorkdayCalculator\API\APIException $e) {
echo '[ERROR]: '.$e->getMessage().PHP_EOL;
} catch (Exception $e) {
echo '[ERROR]: '.$e->getMessage().PHP_EOL;
}
echo $result1->format('Y-m-d').PHP_EOL; // 2019-10-14
echo $result2.PHP_EOL; // 6
reate an instance of the calculator and set the states for german holidays to Hessen.
$calculator = new \OmegaCode\GermanWorkdayCalculator\WorkdayCalculator();
$calculator->setCachePath("/my/custom/cache/path");
// do stuff..
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.