azuyalabs / yasumi

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

BetweenFilter and multiple years #186

Closed lsv closed 4 years ago

lsv commented 4 years ago

So, as we are aproaching new year, it would be great to see this example get updated, because we might actually have 2 different years, as we are close to new year. Or actually in general it would be great to have :)

$start = new DateTime('2019-10-22');
$end = new DateTime('2020-05-22');
$country = 'Italy';

$numberOfHolidaysBetweenDates = 0;
$currentYear = $start->format('Y');
while($currentYear <= $end->format('Y')) {
    $holidays = Yasumi\Yasumi::create($country, $currentYear);
    $numberOfHolidays = $holidays->between(
        $start,
        $end
    );
    $numberOfHolidaysBetweenDates += $numberOfHolidays->count();
    $currentYear++;
}

Is there any better method?

stelgenhof commented 4 years ago

Good question. Actually Yasumi is still tied to a single year so your example is I am afraid the best one. See also the discussion here: https://github.com/azuyalabs/yasumi/issues/131

Neither myself nor anyone has yet investigated this further. I don't expect this will be picked up anytime soon.

github-actions[bot] commented 4 years ago

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