31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
using Elternbeirat.Contracts;
|
|
|
|
namespace Elternbeirat.Web.Features.Events;
|
|
|
|
/// <summary>
|
|
/// Picks the events that still lie ahead.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The events page, the events embed and the "next event" card on the home page
|
|
/// all need the same answer to "what is coming up?". Keeping the rule here means a
|
|
/// change to it (e.g. hiding an event once it has ended) reaches all three.
|
|
/// </remarks>
|
|
/// <seealso cref="Shared.BerlinClock"/>
|
|
public static class UpcomingEvents
|
|
{
|
|
/// <summary>
|
|
/// Returns the events on or after <paramref name="today"/>, earliest first.
|
|
/// </summary>
|
|
/// <param name="events">All events, in any order.</param>
|
|
/// <param name="today">The current day, from <see cref="Shared.BerlinClock.Today"/>.</param>
|
|
/// <returns>The upcoming events, ordered by start.</returns>
|
|
/// <remarks>
|
|
/// Compared by day, not by the minute: an event earlier today still counts as
|
|
/// upcoming, so a visitor who checks during the evening's meeting still finds it.
|
|
/// </remarks>
|
|
public static IEnumerable<Event> From(IEnumerable<Event> events, DateOnly today) =>
|
|
events
|
|
.Where(@event => DateOnly.FromDateTime(@event.Start) >= today)
|
|
.OrderBy(@event => @event.Start);
|
|
}
|