using System.Globalization; using Elternbeirat.Contracts; namespace Elternbeirat.Web.Shared; /// /// Formats an 's date range for display in German. Shared by /// the full event list and the home-page events embed so both render dates the /// same way. /// public static class EventFormat { private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE"); // An event counts as all-day when its start carries no wall-clock time // (00:00); PocketBase has no separate flag. private static bool HasTime(Event ev) => ev.Start.TimeOfDay != TimeSpan.Zero; /// /// Formats the entry's date range: a single day, a date with a time, or a /// span across days. /// public static string Range(Event ev) { var start = HasTime(ev) ? ev.Start.ToString("dddd, d. MMMM yyyy, HH:mm", German) + " Uhr" : ev.Start.ToString("dddd, d. MMMM yyyy", German); if (ev.End is not { } end) { return start; } // Same day: append just the end time. Different days: append the full // end date. if (end.Date == ev.Start.Date) { return HasTime(ev) ? start + "–" + end.ToString("HH:mm", German) + " Uhr" : start; } var endText = HasTime(ev) ? end.ToString("d. MMMM yyyy, HH:mm", German) + " Uhr" : end.ToString("d. MMMM yyyy", German); return start + " – " + endText; } }