Skip to content

Commit

Permalink
Removes redundant condition checks
Browse files Browse the repository at this point in the history
  • Loading branch information
binarygeotech committed Dec 27, 2024
1 parent 9288fe0 commit b396261
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/View/Components/IncidentTimeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,12 @@ public function render(): View
'nextPeriodFrom' => $startDate->clone()->subDays($incidentDays + 1)->toDateString(),
'nextPeriodTo' => $startDate->clone()->addDays($incidentDays + 1)->toDateString(),
'canPageForward' => $this->appSettings->recent_incidents_only ? false : $startDate->clone()->isBefore(now()),
'canPageBackward' => $this->isDateWithinRange($startDate->clone()),
'canPageBackward' => $this->appSettings->recent_incidents_only ? false : true,
'recent_incidents_only' => $this->appSettings->recent_incidents_only,
'recent_incidents_days' => $this->appSettings->recent_incidents_days,
]);
}

private function isDateWithinRange($date)
{
if (!$this->appSettings->recent_incidents_only) {
return true;
}

if ($this->appSettings->recent_incidents_only) {
return false;
}

$minDate = Carbon::now()->subDays($this->appSettings->recent_incidents_days - 1)->startOfDay();
$maxDate = Carbon::now()->endOfDay();

return $date->isBefore($maxDate->addDays(1)) && $date->isAfter($minDate->subDays(1)->endOfDay());
}

/**
* Fetch the incidents that occurred between the given start and end date.
* Incidents will be grouped by days.
Expand Down

0 comments on commit b396261

Please sign in to comment.