Closed pete1019 closed 3 years ago
Hi @pete1019 Sure! For starters to remove holidays from an existing provider, you can use a custom filter. Or more advanced you could create your own custom provider based on an existing one: https://www.yasumi.dev/docs/cookbook/custom_provider/
For the current date, you can use the standard PHP date functions for that: https://www.php.net/manual/en/function.date.php
You can use the isHoliday
method to check if the current day is a holiday or not.
Hope this helps!
@stelgenhof
Thanks. Thought you might be able to post some code here for me to use right away.
To strip it down a little bit this might be enough for now: Print the name like "christmasDay" of the current day.
Again: Thanks lot!
EDIT: GOT IT
if (isset($_GET['c']) && isset($_GET['t'])) {
$tz = $_GET['t'];
if ($tz === 'Default Timezone') {
$tz = `date +%:z`;
}
$dt = new \DateTime('now', new \DateTimeZone($tz));
$c = str_replace('-', "\\", $_GET['c']);
$c = str_replace('-', "//", $c);
$c = str_replace('-', "/", $c);
// $is_holiday = Yasumi\Yasumi::create($c, date('Y'))->isHoliday($dt);
$d = $dt->format('Y-m-d');
#$d = "2021-04-05";
$ho = Yasumi\Yasumi::create($c, date('Y'));
#$official = new Yasumi\Filters\OtherHolidaysFilter($ho->getIterator());
foreach ($ho as $h) {
$shortName = $h->shortName;
if (strval($d) === strval($h))
die($shortName);
}
die("notholiday");
}
@pete1019 Good! A few tips/pointers:
date_default_timezone_get
PHP function to retrieve the default timezone. Not necessary to execute a command via the shellcreateByISO3166_2
function which takes the ISO3166 2 character code of a country (e.g. 'NL', 'DE')strval
(typecasting), as the variables used are already strings. Better is to compare the actual DateTime variables.create
and createByISO3166_2
functions take an integer type variable. The date
function returns a string. You may want to do a type cast here.die
functions are for testing purposes. Better to use exit
or handle the conditions accordingly.Closing, as I assume your question has been answered :)
@stelgenhof yes thanks again!
Hi @stelgenhof,
again: thanks a lot for your great work. need your help on PHP code please. I am not good at all but would love to see your solution. As much detail as possible so i understand.
THANKS A LOT!