Refactor date range calculation in newsletter HTML for index.php and wiki.php. Replaced manual timestamp handling with a streamlined approach using newsletterPeriod function, enhancing code clarity and maintainability.
This commit is contained in:
19
index.php
19
index.php
@@ -347,23 +347,8 @@ function buildNewsletterHtml(array $config, array $articles, string $periodLabel
|
||||
? 'Im Zeitraum ' . h($periodLabel) . ' wurde 1 neuer Wiki-Artikel veröffentlicht.'
|
||||
: 'Im Zeitraum ' . h($periodLabel) . ' wurden ' . $count . ' neue Wiki-Artikel veröffentlicht.';
|
||||
|
||||
$dateRangeText = 'für den Zeitraum ' . h($periodLabel);
|
||||
if (!empty($articles)) {
|
||||
$timestamps = [];
|
||||
foreach ($articles as $article) {
|
||||
$date = DateTimeImmutable::createFromFormat('Y-m-d', (string)($article['date'] ?? ''));
|
||||
if ($date instanceof DateTimeImmutable) {
|
||||
$timestamps[] = $date->getTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($timestamps)) {
|
||||
sort($timestamps);
|
||||
$from = (new DateTimeImmutable('@' . (string)$timestamps[0]))->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
$to = (new DateTimeImmutable('@' . (string)$timestamps[count($timestamps) - 1]))->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
$dateRangeText = 'vom ' . $from->format('d.m.Y') . ' bis ' . $to->format('d.m.Y');
|
||||
}
|
||||
}
|
||||
[$periodStart, $periodEnd] = newsletterPeriod((string)$config['period_mode']);
|
||||
$dateRangeText = 'vom ' . $periodStart->format('d.m.Y') . ' bis ' . $periodEnd->format('d.m.Y');
|
||||
|
||||
$articleRows = '';
|
||||
if ($count === 0) {
|
||||
|
||||
19
wiki.php
19
wiki.php
@@ -347,23 +347,8 @@ function buildNewsletterHtml(array $config, array $articles, string $periodLabel
|
||||
? 'Im Zeitraum ' . h($periodLabel) . ' wurde 1 neuer Wiki-Artikel veröffentlicht.'
|
||||
: 'Im Zeitraum ' . h($periodLabel) . ' wurden ' . $count . ' neue Wiki-Artikel veröffentlicht.';
|
||||
|
||||
$dateRangeText = 'für den Zeitraum ' . h($periodLabel);
|
||||
if (!empty($articles)) {
|
||||
$timestamps = [];
|
||||
foreach ($articles as $article) {
|
||||
$date = DateTimeImmutable::createFromFormat('Y-m-d', (string)($article['date'] ?? ''));
|
||||
if ($date instanceof DateTimeImmutable) {
|
||||
$timestamps[] = $date->getTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($timestamps)) {
|
||||
sort($timestamps);
|
||||
$from = (new DateTimeImmutable('@' . (string)$timestamps[0]))->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
$to = (new DateTimeImmutable('@' . (string)$timestamps[count($timestamps) - 1]))->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
$dateRangeText = 'vom ' . $from->format('d.m.Y') . ' bis ' . $to->format('d.m.Y');
|
||||
}
|
||||
}
|
||||
[$periodStart, $periodEnd] = newsletterPeriod((string)$config['period_mode']);
|
||||
$dateRangeText = 'vom ' . $periodStart->format('d.m.Y') . ' bis ' . $periodEnd->format('d.m.Y');
|
||||
|
||||
$articleRows = '';
|
||||
if ($count === 0) {
|
||||
|
||||
Reference in New Issue
Block a user