aboutsummaryrefslogtreecommitdiffhomepage
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
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)
-rw-r--r--application/front/controller/visitor/DailyController.php2
-rw-r--r--application/helper/DailyPageHelper.php18
-rw-r--r--tests/helper/DailyPageHelperTest.php27
3 files changed, 39 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);
diff --git a/tests/helper/DailyPageHelperTest.php b/tests/helper/DailyPageHelperTest.php
index 5255b7b1..6238e648 100644
--- a/tests/helper/DailyPageHelperTest.php
+++ b/tests/helper/DailyPageHelperTest.php
@@ -121,6 +121,19 @@ class DailyPageHelperTest extends TestCase
121 static::assertEquals($expectedDescription, $description); 121 static::assertEquals($expectedDescription, $description);
122 } 122 }
123 123
124 /**
125 * @dataProvider getDescriptionsByTypeNotIncludeRelative
126 */
127 public function testGeDescriptionsByTypeNotIncludeRelative(
128 string $type,
129 \DateTimeImmutable $dateTime,
130 string $expectedDescription
131 ): void {
132 $description = DailyPageHelper::getDescriptionByType($type, $dateTime, false);
133
134 static::assertEquals($expectedDescription, $description);
135 }
136
124 public function getDescriptionByTypeExceptionUnknownType(): void 137 public function getDescriptionByTypeExceptionUnknownType(): void
125 { 138 {
126 $this->expectException(\Exception::class); 139 $this->expectException(\Exception::class);
@@ -249,6 +262,20 @@ class DailyPageHelperTest extends TestCase
249 } 262 }
250 263
251 /** 264 /**
265 * Data provider for testGeDescriptionsByTypeNotIncludeRelative() test method.
266 */
267 public function getDescriptionsByTypeNotIncludeRelative(): array
268 {
269 return [
270 [DailyPageHelper::DAY, $date = new \DateTimeImmutable(), $date->format('F j, Y')],
271 [DailyPageHelper::DAY, $date = new \DateTimeImmutable('-1 day'), $date->format('F j, Y')],
272 [DailyPageHelper::DAY, new \DateTimeImmutable('2020-10-09 04:05:06'), 'October 9, 2020'],
273 [DailyPageHelper::WEEK, new \DateTimeImmutable('2020-10-09 04:05:06'), 'Week 41 (October 5, 2020)'],
274 [DailyPageHelper::MONTH, new \DateTimeImmutable('2020-10-09 04:05:06'), 'October, 2020'],
275 ];
276 }
277
278 /**
252 * Data provider for testGetDescriptionsByType() test method. 279 * Data provider for testGetDescriptionsByType() test method.
253 */ 280 */
254 public function getRssLengthsByType(): array 281 public function getRssLengthsByType(): array