Daily RSS - Remove relative description (today, yesterday)
It is not useful for the RSS feed, as every new entry will be 'yesterday', and it requires an update the next day.
This commit is contained in:
parent
6f9e0609f4
commit
2883c6d0a7
3 changed files with 39 additions and 8 deletions
application
tests/helper
|
@ -131,7 +131,7 @@ class DailyController extends ShaarliVisitorController
|
||||||
$dataPerDay[$day] = [
|
$dataPerDay[$day] = [
|
||||||
'date' => $endDateTime,
|
'date' => $endDateTime,
|
||||||
'date_rss' => $endDateTime->format(DateTime::RSS),
|
'date_rss' => $endDateTime->format(DateTime::RSS),
|
||||||
'date_human' => DailyPageHelper::getDescriptionByType($type, $dayDateTime),
|
'date_human' => DailyPageHelper::getDescriptionByType($type, $dayDateTime, false),
|
||||||
'absolute_url' => $indexUrl . 'daily?' . $type . '=' . $day,
|
'absolute_url' => $indexUrl . 'daily?' . $type . '=' . $day,
|
||||||
'links' => [],
|
'links' => [],
|
||||||
];
|
];
|
||||||
|
|
|
@ -157,13 +157,17 @@ class DailyPageHelper
|
||||||
* @param string $type month/week/day
|
* @param string $type month/week/day
|
||||||
* @param \DateTimeImmutable $requested DateTime extracted from request input
|
* @param \DateTimeImmutable $requested DateTime extracted from request input
|
||||||
* (should come from extractRequestedDateTime)
|
* (should come from extractRequestedDateTime)
|
||||||
|
* @param bool $includeRelative Include relative date description (today, yesterday, etc.)
|
||||||
*
|
*
|
||||||
* @return string Localized time period description
|
* @return string Localized time period description
|
||||||
*
|
*
|
||||||
* @throws \Exception Type not supported.
|
* @throws \Exception Type not supported.
|
||||||
*/
|
*/
|
||||||
public static function getDescriptionByType(string $type, \DateTimeImmutable $requested): string
|
public static function getDescriptionByType(
|
||||||
{
|
string $type,
|
||||||
|
\DateTimeImmutable $requested,
|
||||||
|
bool $includeRelative = true
|
||||||
|
): string {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case static::MONTH:
|
case static::MONTH:
|
||||||
return $requested->format('F') . ', ' . $requested->format('Y');
|
return $requested->format('F') . ', ' . $requested->format('Y');
|
||||||
|
@ -172,9 +176,9 @@ class DailyPageHelper
|
||||||
return t('Week') . ' ' . $requested->format('W') . ' (' . format_date($requested, false) . ')';
|
return t('Week') . ' ' . $requested->format('W') . ' (' . format_date($requested, false) . ')';
|
||||||
case static::DAY:
|
case static::DAY:
|
||||||
$out = '';
|
$out = '';
|
||||||
if ($requested->format('Ymd') === date('Ymd')) {
|
if ($includeRelative && $requested->format('Ymd') === date('Ymd')) {
|
||||||
$out = t('Today') . ' - ';
|
$out = t('Today') . ' - ';
|
||||||
} elseif ($requested->format('Ymd') === date('Ymd', strtotime('-1 days'))) {
|
} elseif ($includeRelative && $requested->format('Ymd') === date('Ymd', strtotime('-1 days'))) {
|
||||||
$out = t('Yesterday') . ' - ';
|
$out = t('Yesterday') . ' - ';
|
||||||
}
|
}
|
||||||
return $out . format_date($requested, false);
|
return $out . format_date($requested, false);
|
||||||
|
|
|
@ -121,6 +121,19 @@ class DailyPageHelperTest extends TestCase
|
||||||
static::assertEquals($expectedDescription, $description);
|
static::assertEquals($expectedDescription, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getDescriptionsByTypeNotIncludeRelative
|
||||||
|
*/
|
||||||
|
public function testGeDescriptionsByTypeNotIncludeRelative(
|
||||||
|
string $type,
|
||||||
|
\DateTimeImmutable $dateTime,
|
||||||
|
string $expectedDescription
|
||||||
|
): void {
|
||||||
|
$description = DailyPageHelper::getDescriptionByType($type, $dateTime, false);
|
||||||
|
|
||||||
|
static::assertEquals($expectedDescription, $description);
|
||||||
|
}
|
||||||
|
|
||||||
public function getDescriptionByTypeExceptionUnknownType(): void
|
public function getDescriptionByTypeExceptionUnknownType(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
|
@ -248,6 +261,20 @@ class DailyPageHelperTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testGeDescriptionsByTypeNotIncludeRelative() test method.
|
||||||
|
*/
|
||||||
|
public function getDescriptionsByTypeNotIncludeRelative(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[DailyPageHelper::DAY, $date = new \DateTimeImmutable(), $date->format('F j, Y')],
|
||||||
|
[DailyPageHelper::DAY, $date = new \DateTimeImmutable('-1 day'), $date->format('F j, Y')],
|
||||||
|
[DailyPageHelper::DAY, new \DateTimeImmutable('2020-10-09 04:05:06'), 'October 9, 2020'],
|
||||||
|
[DailyPageHelper::WEEK, new \DateTimeImmutable('2020-10-09 04:05:06'), 'Week 41 (October 5, 2020)'],
|
||||||
|
[DailyPageHelper::MONTH, new \DateTimeImmutable('2020-10-09 04:05:06'), 'October, 2020'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data provider for testGetDescriptionsByType() test method.
|
* Data provider for testGetDescriptionsByType() test method.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue