Fixed another bug with the schedule
This commit is contained in:
@@ -53,7 +53,9 @@ QUERY;
|
|||||||
$startDay = $start->format('N');
|
$startDay = $start->format('N');
|
||||||
$endDay = $end->format('N');
|
$endDay = $end->format('N');
|
||||||
$schedule = [];
|
$schedule = [];
|
||||||
|
|
||||||
|
if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$end->format('Y-m-d H:i')}<br/>\n";
|
||||||
|
|
||||||
$START = 1; $END = -1;
|
$START = 1; $END = -1;
|
||||||
$WEEK = new \DateInterval('P7D'); $DAY = new \DateInterval('P1D');
|
$WEEK = new \DateInterval('P7D'); $DAY = new \DateInterval('P1D');
|
||||||
$WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" /* == 0 and 7 */];
|
$WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" /* == 0 and 7 */];
|
||||||
@@ -64,9 +66,11 @@ QUERY;
|
|||||||
foreach($scheduleItems as $item) {
|
foreach($scheduleItems as $item) {
|
||||||
if($item->startdate) { $item->startdate = new \DateTimeImmutable($item->startdate); }
|
if($item->startdate) { $item->startdate = new \DateTimeImmutable($item->startdate); }
|
||||||
if($item->enddate) { $item->enddate = (new \DateTimeImmutable($item->enddate))->add($DAY); }
|
if($item->enddate) { $item->enddate = (new \DateTimeImmutable($item->enddate))->add($DAY); }
|
||||||
|
|
||||||
// Find the start time and end time of the last occurrence on or before the start time
|
// Find the start time and end time of the last occurrence on or before the start time
|
||||||
$itemStart = new \DateTime("last " . $WEEKDAYS[$item->startday] . " " . $start->format('Y-m-d') . " " . $item->starttime);
|
$itemStart = new \DateTime("last " . $WEEKDAYS[$item->startday] . " " . $start->format('Y-m-d') . " " . $item->starttime);
|
||||||
$itemEnd = new \DateTime("last " . $WEEKDAYS[$item->endday] . " " . $start->format('Y-m-d') . " " . $item->endtime);
|
$itemEnd = new \DateTime("last " . $WEEKDAYS[$item->endday] . " " . $start->format('Y-m-d') . " " . $item->endtime);
|
||||||
|
|
||||||
if($itemEnd <= $itemStart) {
|
if($itemEnd <= $itemStart) {
|
||||||
$itemEnd->add($WEEK);
|
$itemEnd->add($WEEK);
|
||||||
}
|
}
|
||||||
@@ -77,9 +81,18 @@ QUERY;
|
|||||||
$itemEnd->add($WEEK);
|
$itemEnd->add($WEEK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a list in which all start and end times are separate entries
|
if($DEBUG) {
|
||||||
$scheduleChanges->insert( [$START, $itemStart, $item], [-$itemStart->getTimestamp(), -$START] );
|
print "Adding {$item->name} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} to {$itemEnd->format('Y-m-d H:i')}.<br/>\n";
|
||||||
$scheduleChanges->insert( [$END, $itemEnd, $item], [-$itemEnd->getTimestamp(), -$END] );
|
if($item->startdate) print " (Item start is {$item->startdate->format('Y-m-d H:i')})<br/>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if((!$item->startdate || $item->startdate <= $itemEnd) && (!$item->enddate || $item->enddate >= $itemStart)) {
|
||||||
|
// Create a list in which all start and end times are separate entries
|
||||||
|
$scheduleChanges->insert( [$START, $itemStart, $item], [-$itemStart->getTimestamp(), -$START] );
|
||||||
|
$scheduleChanges->insert( [$END, $itemEnd, $item], [-$itemEnd->getTimestamp(), -$END] );
|
||||||
|
} else if($DEBUG) {
|
||||||
|
print "Skipping {$item->name} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} because it is out of range.<br/>\n";
|
||||||
|
}
|
||||||
|
|
||||||
// Also keep track of all priorities seen
|
// Also keep track of all priorities seen
|
||||||
$active[$item->priority] = null;
|
$active[$item->priority] = null;
|
||||||
@@ -88,7 +101,7 @@ QUERY;
|
|||||||
if($DEBUG) {
|
if($DEBUG) {
|
||||||
print "<h2>Schedule changes - initial state</h2><ul>";
|
print "<h2>Schedule changes - initial state</h2><ul>";
|
||||||
foreach(clone $scheduleChanges as $c) {
|
foreach(clone $scheduleChanges as $c) {
|
||||||
print "<li>{$c[1]->format('d-m-Y H:i')}: " . ($c[0] == $START ? 'Start' : 'Einde') . " {$c[2]->name} {$c[2]->suffix}</li>";
|
print "<li>#{$c[2]->scheduleid}: {$c[1]->format('d-m-Y H:i')}: " . ($c[0] == $START ? 'Start' : 'Einde') . " {$c[2]->name} {$c[2]->suffix}</li>";
|
||||||
}
|
}
|
||||||
print "</ul><hr/>";
|
print "</ul><hr/>";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user