diff --git a/index.php b/index.php index 855a593..fa149a6 100644 --- a/index.php +++ b/index.php @@ -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']); diff --git a/wiki.php b/wiki.php index 95347d1..8fd0838 100644 --- a/wiki.php +++ b/wiki.php @@ -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) {