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:
smueller
2026-07-07 10:59:07 +02:00
parent 69ba3f1595
commit 91b59f7bc0
2 changed files with 4 additions and 34 deletions

View File

@@ -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) {

View File

@@ -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) {