azuyalabs / yasumi

The easy PHP Library for calculating holidays
https://www.yasumi.dev
Other
1.05k stars 155 forks source link

[Doc / Help] How can we exclude 25 and 26 of december from holidays? #265

Closed realtebo closed 2 years ago

realtebo commented 2 years ago

Yes.. absurd request. I hate my customer ...

I am using your excellent package to exclude holidays when users do orders on a store and choose delivery date.

This year we must allow 25 and 26 december, so we need to filter out these days when checking

                $holidays_in_this_day = $holidays->between(
                    $slot_period->toDate(),
                    $slot_period->toDate()
                );

We would like to DO NOT consider as holidays these 2 days.

How?

realtebo commented 2 years ago

I created a custom provider extending Italy

And did this

/**
 * Initialize holidays for the NYSE.
 * @throws  \Exception
 */
public function initialize(): void
{
    parent::initialize();

    // Remove Columbus Day and Veterans Day
    $this->removeHoliday('christmasDay');
    $this->removeHoliday('stStephensDay');
}

But this year stStephensDay is a Sunday, so I must remove THIS specific sunday.

How ?

stelgenhof commented 2 years ago

@realtebo Thank you for your question! Creating a custom provider is a good option indeed. Alternatively, you can also try creating your own filter where your filter out the unwanted holidays. (https://www.yasumi.dev/docs/cookbook/filters/).

If you use $this->removeHoliday('stStephensDay') does it not do what you need? Looks to me your provider is exactly removing the 25th and the 26th. Or do you get some unexpected results?

github-actions[bot] commented 2 years ago

Since this issue has not had any activity within the last 90 days, I have marked it as stale. I will close it if no further activity occurs within the next 10 days.