From edfa92c1aa1cc62b539e2fc98883a3d7c357ac78 Mon Sep 17 00:00:00 2001 From: tasnim Date: Tue, 27 Aug 2024 09:44:47 +0300 Subject: [PATCH] Navigation.php back and change tests --- app/Support/Navigation.php | 9 ++++++--- tests/unit/Support/NavigationEndOfPeriodTest.php | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index d51ff2cd36..f048ae0f68 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -283,10 +283,13 @@ class Navigation return $currentEnd; } if ('MTD' === $repeatFreq) { - return $end->startOfMonth()->startOfDay(); - } - + $today = today(); + if ($today->isSameMonth($end)) { + return $today->endOfDay(); + } + return $end->endOfMonth(); + } $result = match ($repeatFreq) { 'last7' => $currentEnd->addDays(7)->startOfDay(), diff --git a/tests/unit/Support/NavigationEndOfPeriodTest.php b/tests/unit/Support/NavigationEndOfPeriodTest.php index fdd5e5b7bd..4ee43855da 100644 --- a/tests/unit/Support/NavigationEndOfPeriodTest.php +++ b/tests/unit/Support/NavigationEndOfPeriodTest.php @@ -70,9 +70,10 @@ final class NavigationEndOfPeriodTest extends TestCase 'last30' => ['frequency' => 'last30', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(30)->endOfDay()], 'last90' => ['frequency' => 'last90', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(90)->endOfDay()], 'last365' => ['frequency' => 'last365', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(365)->endOfDay()], - 'MTD' => ['frequency' => 'MTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfMonth()->startOfDay()], + 'MTD' => ['frequency' => 'MTD', 'from' => Carbon::now(), + 'expected' => Carbon::now()->isSameMonth(Carbon::now()) ? Carbon::now()->endOfDay(): Carbon::now()->endOfMonth()], 'QTD' => ['frequency' => 'QTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->firstOfQuarter()->startOfDay()], - 'YTD' => ['frequency' => 'YTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfYear()->startOfDay()], + 'YTD' => ['frequency' => 'YTD', 'from' => Carbon::now(), 'expected' => Carbon::now()->firstOfYear()->startOfDay()], 'week 2023-08-05 to 2023-08-11' => ['frequency' => '1W', 'from' => Carbon::parse('2023-08-05'), 'expected' => Carbon::parse('2023-08-11')->endOfDay()], ]; }