What this code does:
It generates dates based on a single day that is grabbed before ($date
).
It counts always up one week. E.g. If your start date ($date
) is 07.04.2019
it will generate the dates for $final_amount
times.
So, if the start of the date is 07.04.2019
and $final_amount
is: 5
it will output:
07.04.2019` (handled in separate code, as the first day is excluded in code!)
14.04.2019
21.04.2019
28.04.2019
05.04.2019
The issue with my code:
I need to skip the date if it falls into a holiday. So if e.g. 21.04.2019
is a holiday, it should be skipped and replaced with a new date one week later. It should always have the amount $final_amount
even if one ore more dates are laying on a holiday.
I have no Idea how this could be accomplished, as I am relatively new to PHP.
setlocale(LC_TIME, "de_DE"); //only necessary if the locale isn't already set
$date = new DateTime(helper('com://site/ohanah.date.format', array(
'date' => $event->start,
'format' => 'Y-m-d H:i',
'timezone' => 'UTC'
)));
$date_scn = new DateTime(helper('com://site/ohanah.date.format', array(
'date' => $event->end,
'format' => 'H:i',
'timezone' => 'UTC'
)));
$cnt = 2; // start the termin to count at two as the first one is already defined above
$raw_ticket_type = $event->ticket_types->name;
$filter_numbers = array_filter(preg_split('/\D/', $raw_ticket_type));
$filtered_numbers = reset($filter_numbers);
$first_occurence = substr($filtered_numbers[0], 0, 1);
$final_amount = $first_occurence - 1; // subtract 1 from $first_occurence as it is always one more
for ($i = 0; $i < $final_amount; $i++)
{ // loop
$date->add(new DateInterval('P1W')); //add one week
$formatted_time = utf8_encode(strftime("%A, %d. %B %Y, %H:%M", $date->getTimestamp()));
$formatted_time_scnpart = utf8_encode(strftime("%H:%M", $date_scn->getTimestamp()));
// This is the modal
echo '<div class="termin-layout"><span class="termin-number-text">' . $cnt++ . '. ' . 'Termin' . '</span>
<span class="termin-date">' . $formatted_time . ' - ' . $formatted_time_scnpart . '</span></div>';
}
echo '</div></div></div>';