Fixed current day of week calculation
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
namespace Utility
|
||||
using System;
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
public enum Weekday
|
||||
{
|
||||
@ -41,4 +43,35 @@
|
||||
_ => "Unbekannt"
|
||||
};
|
||||
}
|
||||
|
||||
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"
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user