aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/front/controllers/DailyController.php18
-rw-r--r--tests/front/controller/DailyControllerTest.php4
2 files changed, 10 insertions, 12 deletions
diff --git a/application/front/controllers/DailyController.php b/application/front/controllers/DailyController.php
index c2fdaa55..271c0ee2 100644
--- a/application/front/controllers/DailyController.php
+++ b/application/front/controllers/DailyController.php
@@ -30,10 +30,13 @@ class DailyController extends ShaarliController
30 $nbAvailableDates = count($availableDates); 30 $nbAvailableDates = count($availableDates);
31 $index = array_search($day, $availableDates); 31 $index = array_search($day, $availableDates);
32 32
33 if ($index === false && $nbAvailableDates > 0) { 33 if ($index === false) {
34 // no bookmarks for day, but at least one day with bookmarks 34 // no bookmarks for day, but at least one day with bookmarks
35 $index = $nbAvailableDates - 1; 35 $day = $availableDates[$nbAvailableDates - 1] ?? $day;
36 $day = $availableDates[$index]; 36 $previousDay = $availableDates[$nbAvailableDates - 2] ?? '';
37 } else {
38 $previousDay = $availableDates[$index - 1] ?? '';
39 $nextDay = $availableDates[$index + 1] ?? '';
37 } 40 }
38 41
39 if ($day === date('Ymd')) { 42 if ($day === date('Ymd')) {
@@ -42,15 +45,6 @@ class DailyController extends ShaarliController
42 $this->assignView('dayDesc', t('Yesterday')); 45 $this->assignView('dayDesc', t('Yesterday'));
43 } 46 }
44 47
45 if ($index !== false) {
46 if ($index >= 1) {
47 $previousDay = $availableDates[$index - 1];
48 }
49 if ($index < $nbAvailableDates - 1) {
50 $nextDay = $availableDates[$index + 1];
51 }
52 }
53
54 try { 48 try {
55 $linksToDisplay = $this->container->bookmarkService->filterDay($day); 49 $linksToDisplay = $this->container->bookmarkService->filterDay($day);
56 } catch (\Exception $exc) { 50 } catch (\Exception $exc) {
diff --git a/tests/front/controller/DailyControllerTest.php b/tests/front/controller/DailyControllerTest.php
index bb453d5b..2714bfd9 100644
--- a/tests/front/controller/DailyControllerTest.php
+++ b/tests/front/controller/DailyControllerTest.php
@@ -112,6 +112,8 @@ class DailyControllerTest extends TestCase
112 'Daily - '. format_date($currentDay, false, true) .' - Shaarli', 112 'Daily - '. format_date($currentDay, false, true) .' - Shaarli',
113 $assignedVariables['pagetitle'] 113 $assignedVariables['pagetitle']
114 ); 114 );
115 static::assertEquals($currentDay, $assignedVariables['dayDate']);
116 static::assertEquals($currentDay->getTimestamp(), $assignedVariables['day']);
115 static::assertCount(3, $assignedVariables['linksToDisplay']); 117 static::assertCount(3, $assignedVariables['linksToDisplay']);
116 118
117 $link = $assignedVariables['linksToDisplay'][0]; 119 $link = $assignedVariables['linksToDisplay'][0];
@@ -358,6 +360,8 @@ class DailyControllerTest extends TestCase
358 static::assertSame('daily', (string) $result->getBody()); 360 static::assertSame('daily', (string) $result->getBody());
359 static::assertCount(0, $assignedVariables['linksToDisplay']); 361 static::assertCount(0, $assignedVariables['linksToDisplay']);
360 static::assertSame('Today', $assignedVariables['dayDesc']); 362 static::assertSame('Today', $assignedVariables['dayDesc']);
363 static::assertEquals((new \DateTime())->setTime(0, 0)->getTimestamp(), $assignedVariables['day']);
364 static::assertEquals((new \DateTime())->setTime(0, 0), $assignedVariables['dayDate']);
361 } 365 }
362 366
363 protected function createValidContainerMockSet(): void 367 protected function createValidContainerMockSet(): void