From a757f95563260d5f3c8a98e61778486352b03ff5 Mon Sep 17 00:00:00 2001 From: Mae Grace Baybay <87640602+mgbaybay@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:13:16 +0800 Subject: [PATCH] Fixed data calculation for today date range filter (#2856) --- lib/Report/ApiRequests.php | 6 ++++++ lib/Report/DisplayAlerts.php | 6 ++++++ lib/Report/SessionHistory.php | 6 ++++++ lib/Report/TimeDisconnectedSummary.php | 8 ++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Report/ApiRequests.php b/lib/Report/ApiRequests.php index 57f129ff79..df94cf6fc7 100644 --- a/lib/Report/ApiRequests.php +++ b/lib/Report/ApiRequests.php @@ -181,6 +181,12 @@ public function getResults(SanitizerInterface $sanitizedParams) // depending on the date range selected. $fromDt = $sanitizedParams->getDate('fromDt'); $toDt = $sanitizedParams->getDate('toDt'); + $currentDate = Carbon::now()->startOfDay(); + + // If toDt is current date then make it current datetime + if ($toDt->format('Y-m-d') == $currentDate->format('Y-m-d')) { + $toDt = Carbon::now(); + } $type = $sanitizedParams->getString('type'); diff --git a/lib/Report/DisplayAlerts.php b/lib/Report/DisplayAlerts.php index 7b5dd69b3e..10ae1b8873 100644 --- a/lib/Report/DisplayAlerts.php +++ b/lib/Report/DisplayAlerts.php @@ -171,6 +171,12 @@ public function getResults(SanitizerInterface $sanitizedParams) // depending on the date range selected. $fromDt = $sanitizedParams->getDate('fromDt'); $toDt = $sanitizedParams->getDate('toDt'); + $currentDate = Carbon::now()->startOfDay(); + + // If toDt is current date then make it current datetime + if ($toDt->format('Y-m-d') == $currentDate->format('Y-m-d')) { + $toDt = Carbon::now(); + } $metadata = [ 'periodStart' => Carbon::createFromTimestamp($fromDt->toDateTime()->format('U')) diff --git a/lib/Report/SessionHistory.php b/lib/Report/SessionHistory.php index 446c3ea55b..41d6c1593c 100644 --- a/lib/Report/SessionHistory.php +++ b/lib/Report/SessionHistory.php @@ -177,6 +177,12 @@ public function getResults(SanitizerInterface $sanitizedParams) // depending on the date range selected. $fromDt = $sanitizedParams->getDate('fromDt'); $toDt = $sanitizedParams->getDate('toDt'); + $currentDate = Carbon::now()->startOfDay(); + + // If toDt is current date then make it current datetime + if ($toDt->format('Y-m-d') == $currentDate->format('Y-m-d')) { + $toDt = Carbon::now(); + } $metadata = [ 'periodStart' => Carbon::createFromTimestamp($fromDt->toDateTime()->format('U')) diff --git a/lib/Report/TimeDisconnectedSummary.php b/lib/Report/TimeDisconnectedSummary.php index b3d9a1c123..f4afcf925a 100644 --- a/lib/Report/TimeDisconnectedSummary.php +++ b/lib/Report/TimeDisconnectedSummary.php @@ -200,8 +200,6 @@ public function getResults(SanitizerInterface $sanitizedParams) $onlyLoggedIn = $sanitizedParams->getCheckbox('onlyLoggedIn') == 1; $groupBy = $sanitizedParams->getString('groupBy'); - $currentDate = Carbon::now()->startOfDay(); - // // From and To Date Selection // -------------------------- @@ -209,6 +207,12 @@ public function getResults(SanitizerInterface $sanitizedParams) // depending on the date range selected. $fromDt = $sanitizedParams->getDate('fromDt'); $toDt = $sanitizedParams->getDate('toDt'); + $currentDate = Carbon::now()->startOfDay(); + + // If toDt is current date then make it current datetime + if ($toDt->format('Y-m-d') == $currentDate->format('Y-m-d')) { + $toDt = Carbon::now(); + } // Get an array of display groups this user has access to $displayGroupIds = [];