Skip to content

Commit

Permalink
Support conditions with alternative calendar
Browse files Browse the repository at this point in the history
Fix #84
  • Loading branch information
kylekatarnls committed Oct 18, 2024
1 parent b8efade commit 8a5d381
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Cmixin/BusinessDay/Calculator/HolidayCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,23 @@ protected function calculateDynamicHoliday(string $holiday, &$dateTime = null, $

[$before, $after, $holiday] = $this->extractModifiers($holiday);

['start' => $start, 'end' => $end] = preg_match('/^(?<start>.*?)(?<end> (?:if|on|not on).*)$/', $holiday, $match)
? $match
: ['start' => $holiday, 'end' => null];

foreach ($this->calendars as $calendar) {
if (preg_match('/^\s*(\d+)\s+('.$calendar->getRegex().')\s*$/i', $holiday, $match)) {
if (preg_match('/^\s*(\d+)\s+('.$calendar->getRegex().')\s*$/i', $start, $match)) {
[$result, $nextHolidays] = $calendar->getHolidays($this->year, $match[1], $match[2], $key);

$this->nextHolidays = $nextHolidays;

return $result;
if (!$end) {
return $result;
}

$holiday = $result.$end;

break;
}
}

Expand Down

0 comments on commit 8a5d381

Please sign in to comment.