Update date range handling in newsletter HTML for index.php and wiki.php. Adjusted end date calculation for current month and refined date range display logic to improve clarity and accuracy in article summaries.

This commit is contained in:
smueller
2026-07-07 11:03:56 +02:00
parent 91b59f7bc0
commit d1e3ccc00c
2 changed files with 48 additions and 9 deletions

View File

@@ -285,7 +285,7 @@ function newsletterPeriod(string $mode): array
if ($mode === 'current_month') {
$start = $now->modify('first day of this month')->setTime(0, 0, 0);
$end = $now->modify('first day of next month')->setTime(0, 0, 0);
$end = $now->modify('tomorrow')->setTime(0, 0, 0);
} else {
$start = $now->modify('first day of previous month')->setTime(0, 0, 0);
$end = $now->modify('first day of this month')->setTime(0, 0, 0);
@@ -344,11 +344,31 @@ function buildNewsletterHtml(array $config, array $articles, string $periodLabel
$replyEmail = trim((string)($config['reply_to'] ?: $config['from_email']));
$replyHref = 'mailto:' . $replyEmail;
$summaryText = $count === 1
? 'Im Zeitraum ' . h($periodLabel) . ' wurde 1 neuer Wiki-Artikel veröffentlicht.'
: 'Im Zeitraum ' . h($periodLabel) . ' wurden ' . $count . ' neue Wiki-Artikel veröffentlicht.';
? 'In diesem Zeitraum wurde 1 neuer Wiki-Artikel veröffentlicht.'
: 'In diesem Zeitraum wurden ' . $count . ' neue Wiki-Artikel veröffentlicht.';
[$periodStart, $periodEnd] = newsletterPeriod((string)$config['period_mode']);
$dateRangeText = 'vom ' . $periodStart->format('d.m.Y') . ' bis ' . $periodEnd->format('d.m.Y');
$rangeEnd = $periodEnd;
if (($config['period_mode'] ?? '') === 'current_month') {
$rangeEnd = new DateTimeImmutable('today');
}
$dateRangeText = 'vom ' . $periodStart->format('d.m') . ' bis ' . $rangeEnd->format('d.m');
if ($isTest && !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') . ' bis ' . $to->format('d.m');
}
}
$articleRows = '';
if ($count === 0) {
@@ -632,7 +652,6 @@ function newsletterData(array $config, bool $testMode = false): array
if ($testMode) {
$articles = array_slice($allArticles, 0, (int)$config['article_limit']);
$periodLabel = 'aktuelle Übersicht';
$periodKey = 'test-' . date('Y-m-d-H-i-s');
} else {
$articles = filterArticlesForPeriod($allArticles, $start, $end, (int)$config['article_limit']);

View File

@@ -285,7 +285,7 @@ function newsletterPeriod(string $mode): array
if ($mode === 'current_month') {
$start = $now->modify('first day of this month')->setTime(0, 0, 0);
$end = $now->modify('first day of next month')->setTime(0, 0, 0);
$end = $now->modify('tomorrow')->setTime(0, 0, 0);
} else {
$start = $now->modify('first day of previous month')->setTime(0, 0, 0);
$end = $now->modify('first day of this month')->setTime(0, 0, 0);
@@ -344,11 +344,31 @@ function buildNewsletterHtml(array $config, array $articles, string $periodLabel
$replyEmail = trim((string)($config['reply_to'] ?: $config['from_email']));
$replyHref = 'mailto:' . $replyEmail;
$summaryText = $count === 1
? 'Im Zeitraum ' . h($periodLabel) . ' wurde 1 neuer Wiki-Artikel veröffentlicht.'
: 'Im Zeitraum ' . h($periodLabel) . ' wurden ' . $count . ' neue Wiki-Artikel veröffentlicht.';
? 'In diesem Zeitraum wurde 1 neuer Wiki-Artikel veröffentlicht.'
: 'In diesem Zeitraum wurden ' . $count . ' neue Wiki-Artikel veröffentlicht.';
[$periodStart, $periodEnd] = newsletterPeriod((string)$config['period_mode']);
$dateRangeText = 'vom ' . $periodStart->format('d.m.Y') . ' bis ' . $periodEnd->format('d.m.Y');
$rangeEnd = $periodEnd;
if (($config['period_mode'] ?? '') === 'current_month') {
$rangeEnd = new DateTimeImmutable('today');
}
$dateRangeText = 'vom ' . $periodStart->format('d.m') . ' bis ' . $rangeEnd->format('d.m');
if ($isTest && !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') . ' bis ' . $to->format('d.m');
}
}
$articleRows = '';
if ($count === 0) {