Add the Chronological
This commit is contained in:
71
src/ChronologicalDayTemplate.php
Normal file
71
src/ChronologicalDayTemplate.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user