Closed pete1019 closed 3 years ago
Hi @pete1019 It is indeed not correct to show this as an official holiday. In many countries this is often just observed and in some business sectors people may get off work earlier.
Hi @stelgenhof
yes they may get off work ealier but for example: we use yasumi for a PBX. And now if someone calls on the 31st of december at 9 o clock it will tell them right away: its a Holiday. This is a problem since it is NOT a holiday in Germany.
Any ideas? Fix?
Thanks
@pete1019 Yes, it is possible to reclassify this day as a non-official day. It will then not appear in the list of official holidays. Alternative you can create a custom filter to filter out any holidays you seem not relevant for your situation.
@stelgenhof will this be a pull request / change you will do? Available in next version? Filters are explained in docs?
@pete1019 Yes, here you can find how to use one of the filters that come with Yasumi: https://www.yasumi.dev/docs/cookbook/filters/ However, to make your own filter there is no such documentation for that. I would recommend to look at the source and see how it is done. It is pretty simple to create your own filter.
As for a fix, I can make change soon that will be in a next release.
Thanks a lot for your effort!
@pete1019 After looking into this, New Years Eve in Germany is not classified as an 'official' holiday in Yasumi. It is marked as 'OTHER' so all is good here :)
What perhaps you have seen is that when you use Yasumi, it will return all holidays that are registered in Yasumi for your country. That means official, seasonal, bank holidays and other types. If you only need the official ones you need to use the 'Official' filter as explained here: https://www.yasumi.dev/docs/cookbook/filters/
Cheers! Sacha
@stelgenhof what i need is the "isHoliday" function but only with "Official". How is that possible? Thanks a lot!
@pete1019 The functionisHoliday
determines only if the given date is a Yasumi holiday for the respective holiday provider. Not a holiday in the sense of a non-working day. Perhaps the term holiday
used in Yasumi is a bit confusing: in Yasumi it means a day that is recognized as being an event that is celebrated or recognized for various reasons (tradition, religion, national events, global events, etc.).
If you only need the "Official" holidays, you can use the filters as suggested.
Cheers! Sacha
@stelgenhof Thanks for your fast replay, Sacha. But this does not work but was working before we used "Official". Please help.
$holidays1 = Yasumi\Yasumi::create($c, date('Y'));
$holidays1 = new Yasumi\Filters\OfficialHolidaysFilter($holidays1->getIterator());
$holidays2 = Yasumi\Yasumi::create($c, date('Y') + 1);
$holidays2 = new Yasumi\Filters\OfficialHolidaysFilter($holidays2->getIterator());
$dates1 = $holidays1;
$dates2 = $holidays2;
$result = [
'year1' => $dates1,
'year2' => $dates2,
];
In the end i want to check if a specific date isHoliday (Official) (is_Holiday.php)
And on a other page i want the Name and Dates of year 2021 and 2022 (Official) (List_Holiday.php) Listed one by one each row.
This works fine but NOT when i try to do it with "Official".
This worked before (but NOT with Official anymore): $holidays1 = Yasumi\Yasumi::create($c, date('Y')); $dates1 = $holidays1->getHolidayDates(); $holidays2 = Yasumi\Yasumi::create($c, date('Y') + 1); $dates2 = $holidays2->getHolidayDates();
$result = [ 'year1' => $dates1, 'year2' => $dates2, ];
Thanks a lot!
Hi @pete1019 ,
Apologies for the delayed response. I am not familiar with your other code (is_Holiday.php
and List_Holiday.php
), but the filters in Yasumi are an extension of https://php.net/manual/en/class.filteriterator.php so they don't return an array as such.
You need to do some processing/iteration of the filter results. What exactly depends a bit on your use case.
I've updated your example code so the result contains an array of Holiday objects:
$c = 'Germany';
$holidays1 = Yasumi\Yasumi::create($c, (int) date('Y'));
$holidays1 = new Yasumi\Filters\OfficialHolidaysFilter($holidays1->getIterator());
$holidays2 = Yasumi\Yasumi::create($c, (int) date('Y') + 1);
$holidays2 = new Yasumi\Filters\OfficialHolidaysFilter($holidays2->getIterator());
$dates1 = $holidays1;
$dates2 = $holidays2;
$result = [
'year1' => iterator_to_array($dates1->getInnerIterator()),
'year2' => iterator_to_array($dates2->getInnerIterator()),
];
Cheers! Sacha
@stelgenhof Thank you for taking your time.
last thing i do is:
die(json_encode([ 'result' => $result, ])); }
I tried your lines and but i don't get the dates back in a list but "[object Object]" (see below).
Would be great if you could help again.
This is what i do for output.
` $timezone = $data['timezone']; $country_esc = str_replace("\", "-", $data['country']); $country_esc = str_replace("//", "-", $country_esc); $country_esc = str_replace("/", "-", $country_esc); $desc = $country_esc . ' ' . $timezone; $params = 'c=' . $country_esc . '&t=' . urlencode($timezone);
// Check if country is valid
if (
!in_array(
$data['country'],
array_values(Yasumi\Yasumi::getProviders())
)
) {
http_response_code(400);
die(json_encode([
'error' => 'Invalid country'
]));
}`
This is my result showing:
newYearsDay: [object Object] goodFriday: [object Object] easterMonday: [object Object] internationalWorkersDay: [object Object] ascensionDay: [object Object] pentecostMonday: [object Object] germanUnityDay: [object Object] reformationDay: [object Object] repentanceAndPrayerDay: [object Object] christmasDay: [object Object] secondChristmasDay: [object Object] newYearsEve: [object Object] newYearsDay: [object Object] goodFriday: [object Object] easterMonday: [object Object] internationalWorkersDay: [object Object] ascensionDay: [object Object] pentecostMonday: [object Object] germanUnityDay: [object Object] reformationDay: [object Object] repentanceAndPrayerDay: [object Object] christmasDay: [object Object] secondChristmasDay: [object Object] newYearsEve: [object Object]
Hi @pete1019 My code was just an example. You can just use any of the object methods you need. I actually don't know what you want to do or what you would like to see. Can you show me what output you like to have? It is a bit guessing for me... :)
Cheers! Sacha
@stelgenhof
Sure i just want to have this output but with the filter applied (so after Filter: no newYearsEve should show):
newYearsDay: 2021-01-01 epiphany: 2021-01-06 goodFriday: 2021-04-02 easterMonday: 2021-04-05 internationalWorkersDay: 2021-05-01 ascensionDay: 2021-05-13 pentecostMonday: 2021-05-24 corpusChristi: 2021-06-03 germanUnityDay: 2021-10-03 allSaintsDay: 2021-11-01 christmasDay: 2021-12-25 secondChristmasDay: 2021-12-26 newYearsEve: 2021-12-31
For the resent year and the year after. That is what the year + 1 is for.
THANKS a lot!
Hi @pete1019 Thank you! In that case you can just exactly follow the Official Filter example in the documentation: https://www.yasumi.dev/docs/cookbook/filters/
Keep in mind that the filters are iterators, so you need to handle them accordingly. Normally you would loop through the result as explained in the example. That will give you the output you want.
Cheers! Sacha
@stelgenhof but i need the Holidays + the dates as mentioned.
@pete1019 Yes, in the example, this part:
foreach ($official as $day) {
echo $day->getName() . PHP_EOL;
}
only displays the name. Since a Yasumi class is an extension of PHP's DateTime class, you can use those methods as well (e.g. format
).
So you could do something simple like this:
$result = [];
foreach ($official as $day) {
$results[] = [ $day->getName(), $day->format('Y-m-d')];
}
Cheers! Sacha
Hello, thanks a lot for the effort you put into yasumi.
It shows for today (2020-12-31 New Year’s Eve) Holiday
But officially there is no holiday today.
Lets discuss!
Thanks