Skip to content

Commit

Permalink
Avoid errors when end_time is not specified (#604)
Browse files Browse the repository at this point in the history
I'm not sure if this code ever worked. The old code was running
date_add on the start_time as a string instead of an object.

I re-organized the code a little to make it more readable.
  • Loading branch information
jmcclelland authored May 21, 2024
1 parent e827d80 commit 5bcaa1f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CRM/Volunteer/Page/Roster.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ private function isAssignmentInThePast(array $assignment){
return TRUE;
}

// In case there is no end time and no duration, we use the start date as
// our default end date.
$endTime = new DateTime($assignment['start_time']);
$startTime = new DateTime($assignment['start_time']);
if (!empty($assignment['end_time'])) {
$endTime = new DateTime($assignment['end_time']);
} elseif (!empty($assignment['duration'])) {
$endTime = date_add($assignment['start_time'], new DateInterval('PT' . $assignment['duration'] . 'M'));
$endTime = date_add($startTime, new DateInterval('PT' . $assignment['duration'] . 'M'));
} else {
// In case there is no end time and no duration, we use the start date as
// our default end date.
$endTime = $startTime;
}

return $this->todaysDate > $endTime;
Expand Down

0 comments on commit 5bcaa1f

Please sign in to comment.