36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
|
using System;
|
|||
|
|
|||
|
namespace Utility
|
|||
|
{
|
|||
|
public static class DayOfWeekExtension
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Gibt den Wochentag zurück, der auf den gegebenen Wochentag folgt.
|
|||
|
/// </summary>
|
|||
|
public static DayOfWeek GetNext(this DayOfWeek current) => GetFutureDay(current, 1);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gibt den Wochentag zurück, der in der gegebenen Anzahl an Tagen auf den gegebenen Wochentag folgt.
|
|||
|
/// </summary>
|
|||
|
/// <param name="current">Der aktuelle Wochentag.</param>
|
|||
|
/// <param name="days">Die Anzahl an Tagen, die vergehen sollen.</param>
|
|||
|
public static DayOfWeek GetFutureDay(this DayOfWeek current, int days) =>
|
|||
|
(DayOfWeek)(((int)current + days) % 7);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gibt den deutschen Namen des Wochentags zurück.
|
|||
|
/// </summary>
|
|||
|
public static string GetName(this DayOfWeek weekday) => weekday switch
|
|||
|
{
|
|||
|
DayOfWeek.Monday => "Montag",
|
|||
|
DayOfWeek.Tuesday => "Dienstag",
|
|||
|
DayOfWeek.Wednesday => "Mittwoch",
|
|||
|
DayOfWeek.Thursday => "Donnerstag",
|
|||
|
DayOfWeek.Friday => "Freitag",
|
|||
|
DayOfWeek.Saturday => "Samstag",
|
|||
|
DayOfWeek.Sunday => "Sonntag",
|
|||
|
_ => "Unbekannt"
|
|||
|
};
|
|||
|
}
|
|||
|
}
|