aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/front/controller/visitor/DailyController.php2
-rw-r--r--application/helper/DailyPageHelper.php18
2 files changed, 12 insertions, 8 deletions
diff --git a/application/front/controller/visitor/DailyController.php b/application/front/controller/visitor/DailyController.php
index 846cfe22..5ae89299 100644
--- a/application/front/controller/visitor/DailyController.php
+++ b/application/front/controller/visitor/DailyController.php
@@ -131,7 +131,7 @@ class DailyController extends ShaarliVisitorController
131 $dataPerDay[$day] = [ 131 $dataPerDay[$day] = [
132 'date' => $endDateTime, 132 'date' => $endDateTime,
133 'date_rss' => $endDateTime->format(DateTime::RSS), 133 'date_rss' => $endDateTime->format(DateTime::RSS),
134 'date_human' => DailyPageHelper::getDescriptionByType($type, $dayDateTime), 134 'date_human' => DailyPageHelper::getDescriptionByType($type, $dayDateTime, false),
135 'absolute_url' => $indexUrl . 'daily?' . $type . '=' . $day, 135 'absolute_url' => $indexUrl . 'daily?' . $type . '=' . $day,
136 'links' => [], 136 'links' => [],
137 ]; 137 ];
diff --git a/application/helper/DailyPageHelper.php b/application/helper/DailyPageHelper.php
index 5fabc907..9bdb7ba5 100644
--- a/application/helper/DailyPageHelper.php
+++ b/application/helper/DailyPageHelper.php
@@ -154,16 +154,20 @@ class DailyPageHelper
154 * Get localized description of the time period depending on given datetime and type. 154 * Get localized description of the time period depending on given datetime and type.
155 * Example: for a month period, it returns `October, 2020`. 155 * Example: for a month period, it returns `October, 2020`.
156 * 156 *
157 * @param string $type month/week/day 157 * @param string $type month/week/day
158 * @param \DateTimeImmutable $requested DateTime extracted from request input 158 * @param \DateTimeImmutable $requested DateTime extracted from request input
159 * (should come from extractRequestedDateTime) 159 * (should come from extractRequestedDateTime)
160 * @param bool $includeRelative Include relative date description (today, yesterday, etc.)
160 * 161 *
161 * @return string Localized time period description 162 * @return string Localized time period description
162 * 163 *
163 * @throws \Exception Type not supported. 164 * @throws \Exception Type not supported.
164 */ 165 */
165 public static function getDescriptionByType(string $type, \DateTimeImmutable $requested): string 166 public static function getDescriptionByType(
166 { 167 string $type,
168 \DateTimeImmutable $requested,
169 bool $includeRelative = true
170 ): string {
167 switch ($type) { 171 switch ($type) {
168 case static::MONTH: 172 case static::MONTH:
169 return $requested->format('F') . ', ' . $requested->format('Y'); 173 return $requested->format('F') . ', ' . $requested->format('Y');
@@ -172,9 +176,9 @@ class DailyPageHelper
172 return t('Week') . ' ' . $requested->format('W') . ' (' . format_date($requested, false) . ')'; 176 return t('Week') . ' ' . $requested->format('W') . ' (' . format_date($requested, false) . ')';
173 case static::DAY: 177 case static::DAY:
174 $out = ''; 178 $out = '';
175 if ($requested->format('Ymd') === date('Ymd')) { 179 if ($includeRelative && $requested->format('Ymd') === date('Ymd')) {
176 $out = t('Today') . ' - '; 180 $out = t('Today') . ' - ';
177 } elseif ($requested->format('Ymd') === date('Ymd', strtotime('-1 days'))) { 181 } elseif ($includeRelative && $requested->format('Ymd') === date('Ymd', strtotime('-1 days'))) {
178 $out = t('Yesterday') . ' - '; 182 $out = t('Yesterday') . ' - ';
179 } 183 }
180 return $out . format_date($requested, false); 184 return $out . format_date($requested, false);