72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace dokuwiki\plugin\luxtools;
|
|
|
|
/**
|
|
* Builds page template content for chronological day pages.
|
|
*/
|
|
class ChronologicalDayTemplate
|
|
{
|
|
/**
|
|
* Build a German date heading template for a canonical day ID.
|
|
*
|
|
* Example output:
|
|
* ====== Freitag, 13. Februar 2026 ======
|
|
*
|
|
* @param string $dayId
|
|
* @param string $baseNs
|
|
* @return string|null
|
|
*/
|
|
public static function buildForDayId(string $dayId, string $baseNs = 'chronological'): ?string
|
|
{
|
|
$parts = ChronoID::parseDayId($dayId, $baseNs);
|
|
if ($parts === null) return null;
|
|
|
|
$formatted = self::formatGermanDate($parts['year'], $parts['month'], $parts['day']);
|
|
return '====== ' . $formatted . " ======\n\n";
|
|
}
|
|
|
|
/**
|
|
* Format date with German day/month names and style:
|
|
* Freitag, 13. Februar 2026
|
|
*
|
|
* @param int $year
|
|
* @param int $month
|
|
* @param int $day
|
|
* @return string
|
|
*/
|
|
protected static function formatGermanDate(int $year, int $month, int $day): string
|
|
{
|
|
$weekdays = [
|
|
1 => 'Montag',
|
|
2 => 'Dienstag',
|
|
3 => 'Mittwoch',
|
|
4 => 'Donnerstag',
|
|
5 => 'Freitag',
|
|
6 => 'Samstag',
|
|
7 => 'Sonntag',
|
|
];
|
|
|
|
$months = [
|
|
1 => 'Januar',
|
|
2 => 'Februar',
|
|
3 => 'März',
|
|
4 => 'April',
|
|
5 => 'Mai',
|
|
6 => 'Juni',
|
|
7 => 'Juli',
|
|
8 => 'August',
|
|
9 => 'September',
|
|
10 => 'Oktober',
|
|
11 => 'November',
|
|
12 => 'Dezember',
|
|
];
|
|
|
|
$weekdayIndex = (int)date('N', mktime(0, 0, 0, $month, $day, $year));
|
|
$weekday = $weekdays[$weekdayIndex] ?? '';
|
|
$monthName = $months[$month] ?? '';
|
|
|
|
return sprintf('%s, %d. %s %d', $weekday, $day, $monthName, $year);
|
|
}
|
|
}
|