aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/helper
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-12-16 16:04:53 +0100
committerGitHub <noreply@github.com>2020-12-16 16:04:53 +0100
commitab4c170672c0679c5b8ebc6065e3ca2b13165f24 (patch)
tree173cd95c3b6d4972dcc8b003a6a225e8eb8d5f4e /application/helper
parentbd11879018416d2c5d87728bb0be6ee0cf54451a (diff)
parent2883c6d0a71db174ee8df7548178a8fbee486e25 (diff)
downloadShaarli-ab4c170672c0679c5b8ebc6065e3ca2b13165f24.tar.gz
Shaarli-ab4c170672c0679c5b8ebc6065e3ca2b13165f24.tar.zst
Shaarli-ab4c170672c0679c5b8ebc6065e3ca2b13165f24.zip
Merge pull request #1644 from ArthurHoaro/fix/daily-rss
Daily RSS - Remove relative description (today, yesterday)
Diffstat (limited to 'application/helper')
-rw-r--r--application/helper/DailyPageHelper.php18
1 files changed, 11 insertions, 7 deletions
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);