diff --git a/index.php b/index.php index 2733deb..855a593 100644 --- a/index.php +++ b/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) { diff --git a/wiki.php b/wiki.php index f30e226..95347d1 100644 --- a/wiki.php +++ b/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) {