38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Globalization;
|
||
using Elternbeirat.Web.Services;
|
||
|
||
namespace Elternbeirat.Web.Features.Events;
|
||
|
||
public partial class EventList
|
||
{
|
||
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
||
|
||
// Formats the entry's date range for display: a single day, a date with a
|
||
// time, or a span across days.
|
||
private static string Format(Event ev)
|
||
{
|
||
var start = ev.HasTime
|
||
? 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 ev.HasTime
|
||
? start + "–" + end.ToString("HH:mm", German) + " Uhr"
|
||
: start;
|
||
}
|
||
|
||
var endText = ev.HasTime
|
||
? end.ToString("d. MMMM yyyy, HH:mm", German) + " Uhr"
|
||
: end.ToString("d. MMMM yyyy", German);
|
||
return start + " – " + endText;
|
||
}
|
||
}
|