azuyalabs / yasumi

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

Custom Holiday #230

Closed sebastianpisula closed 3 years ago

sebastianpisula commented 4 years ago

Hi,

I would like to use Yasumi as engine for calculation for delivery date but I would like to include holiday (for example seller has holiday).

$holidays = Yasumi::create( 'Poland', 2020 );
$holidays->addHoliday( new Holiday( 'Holiday 1', [], new DateTimeImmutable( '2020-08-27' ) ) );
$holidays->addHoliday( new Holiday( 'Holiday 2', [], new DateTimeImmutable( '2020-08-28' ) ) );

echo Yasumi::nextWorkingDay( 'Poland', new DateTimeImmutable( '2020-08-26' ) )->format( 'Y-m-d' );

Expected result: 2020-08-31

stelgenhof commented 4 years ago

Thank you @sebastianpisula Let me have a look and get back to you.

stelgenhof commented 4 years ago

@sebastianpisula You should use the workingDays parameter of the nextWorkingDay function, which tells until how many days ahead Yasumi need to look for the next working day.

However I think this function is broken, as my tests don't give the expected next working day even after setting the appropriate workingDays value.

github-actions[bot] commented 3 years ago

This issue has been open 60 days with no activity. Please remove the stale label or comment, or this will be closed in 10 days.

sebastianpisula commented 1 year ago

It still doesn't work correctly. I expect that if I have holidays in Poland, and I add a new date, Yasumi::nextWorkingDay will take this into account. For example - in Poland we have holidays on December 24th, 25th, and 26th. If I add December 27th and run the script with the date 23rd, I expect that the next working day will be December 28th.

$holidays = Yasumi::create( 'Poland', 2022 ); $holidays->addHoliday( new Holiday( 'Holiday 1', [], new \DateTimeImmutable( '2022-12-27' ) ) );

var_dump( Yasumi::nextWorkingDay( 'Poland', new \DateTimeImmutable('2022-12-23') )->format( 'Y-m-d' ) );

stelgenhof commented 1 year ago

@sebastianpisula Thanks for the feedback. I will have a look later this week.