Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m8s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m5s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m6s
CI / Build-Artefakte aktuell (pull_request) Failing after 43s
- Neuigkeiten mit Kategorien, Titelbild (WebP-Varianten), Lesezeit, geplanter Veröffentlichung und Hervorhebung; Text wird beim Speichern bereinigt - Termine mit Ort, Online-Link, ganztägigen Terminen und .ics-Export - Startseite nach Intranet-Vorbild: Slider, Neuigkeiten, Termine, Aktuelles aus den Bereichen; mobil in sinnvoller Reihenfolge - Admin: Beiträge, Kategorien und Termine - Bildverarbeitung für Shared Hosting: nur eine Vollbild-Kopie im Speicher, Speicherlimit bei Bedarf auf 256 MB angehoben (wie WordPress) - Demo-Inhalte für die Entwicklung Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
50 lines
2.6 KiB
JavaScript
50 lines
2.6 KiB
JavaScript
const dateFormat = new Intl.DateTimeFormat('de-DE', { day: 'numeric', month: 'long', year: 'numeric' });
|
||
const shortDateFormat = new Intl.DateTimeFormat('de-DE', { day: 'numeric', month: 'short', year: 'numeric' });
|
||
const timeFormat = new Intl.DateTimeFormat('de-DE', { hour: '2-digit', minute: '2-digit' });
|
||
const weekdayFormat = new Intl.DateTimeFormat('de-DE', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' });
|
||
const monthFormat = new Intl.DateTimeFormat('de-DE', { month: 'short' });
|
||
const monthYearFormat = new Intl.DateTimeFormat('de-DE', { month: 'long', year: 'numeric' });
|
||
const relative = new Intl.RelativeTimeFormat('de-DE', { numeric: 'auto' });
|
||
|
||
export const formatDate = (iso) => dateFormat.format(new Date(iso));
|
||
export const formatShortDate = (iso) => shortDateFormat.format(new Date(iso));
|
||
export const formatWeekdayDate = (iso) => weekdayFormat.format(new Date(iso));
|
||
export const formatTime = (iso) => timeFormat.format(new Date(iso));
|
||
export const formatMonthYear = (iso) => monthYearFormat.format(new Date(iso));
|
||
|
||
/** „vor 2 Stunden“, „gestern“ – ab einer Woche das Datum. */
|
||
export function formatRelative(iso) {
|
||
const date = new Date(iso);
|
||
const seconds = (date.getTime() - Date.now()) / 1000;
|
||
const abs = Math.abs(seconds);
|
||
|
||
if (abs < 60) return 'gerade eben';
|
||
if (abs < 3600) return relative.format(Math.round(seconds / 60), 'minute');
|
||
if (abs < 86400) return relative.format(Math.round(seconds / 3600), 'hour');
|
||
if (abs < 7 * 86400) return relative.format(Math.round(seconds / 86400), 'day');
|
||
|
||
return formatDate(iso);
|
||
}
|
||
|
||
/** Tag und Monat für Datumsblöcke („22“ / „MAI“). */
|
||
export function dateBlock(iso) {
|
||
const date = new Date(iso);
|
||
|
||
return { day: date.getDate(), month: monthFormat.format(date).replace('.', '').toUpperCase() };
|
||
}
|
||
|
||
/** Zeitraum eines Termins in lesbarer Form. */
|
||
export function formatEventRange(event) {
|
||
const start = new Date(event.starts_at);
|
||
const end = event.ends_at ? new Date(event.ends_at) : null;
|
||
const sameDay = end && start.toDateString() === end.toDateString();
|
||
|
||
if (event.all_day) {
|
||
return end && !sameDay ? `${formatShortDate(event.starts_at)} – ${formatShortDate(event.ends_at)}` : `${formatShortDate(event.starts_at)}, ganztägig`;
|
||
}
|
||
|
||
if (!end) return `${formatShortDate(event.starts_at)}, ${formatTime(event.starts_at)} Uhr`;
|
||
if (sameDay) return `${formatShortDate(event.starts_at)}, ${formatTime(event.starts_at)} – ${formatTime(event.ends_at)} Uhr`;
|
||
|
||
return `${formatShortDate(event.starts_at)}, ${formatTime(event.starts_at)} Uhr – ${formatShortDate(event.ends_at)}, ${formatTime(event.ends_at)} Uhr`;
|
||
}
|