- $day = $request->getQueryParam('day') ?? date('Ymd');
-
- $availableDates = $this->container->bookmarkService->days();
- $nbAvailableDates = count($availableDates);
- $index = array_search($day, $availableDates);
-
- if ($index === false) {
- // no bookmarks for day, but at least one day with bookmarks
- $day = $availableDates[$nbAvailableDates - 1] ?? $day;
- $previousDay = $availableDates[$nbAvailableDates - 2] ?? '';
- } else {
- $previousDay = $availableDates[$index - 1] ?? '';
- $nextDay = $availableDates[$index + 1] ?? '';
- }
-
- if ($day === date('Ymd')) {
- $this->assignView('dayDesc', t('Today'));
- } elseif ($day === date('Ymd', strtotime('-1 days'))) {
- $this->assignView('dayDesc', t('Yesterday'));
- }
-
- try {
- $linksToDisplay = $this->container->bookmarkService->filterDay($day);
- } catch (\Exception $exc) {
- $linksToDisplay = [];
- }
+ $type = DailyPageHelper::extractRequestedType($request);
+ $format = DailyPageHelper::getFormatByType($type);
+ $latestBookmark = $this->container->bookmarkService->getLatest();
+ $dateTime = DailyPageHelper::extractRequestedDateTime($type, $request->getQueryParam($type), $latestBookmark);
+ $start = DailyPageHelper::getStartDateTimeByType($type, $dateTime);
+ $end = DailyPageHelper::getEndDateTimeByType($type, $dateTime);
+ $dailyDesc = DailyPageHelper::getDescriptionByType($type, $dateTime);
+
+ $linksToDisplay = $this->container->bookmarkService->findByDate(
+ $start,
+ $end,
+ $previousDay,
+ $nextDay
+ );