/// <summary> /// Converts the <see cref="DayOfWeek" /> into a <see cref="Weekday" />. /// </summary> /// <param name="dayOfWeek"></param> /// <returns></returns> public static Weekday WeekdayForDayOfWeek(DayOfWeek dayOfWeek) { int weekdayNumber = (int)dayOfWeek; if (dayOfWeek == DayOfWeek.Sunday) { // Sunday is 0 but should be 7 for an ISO compliant weekday weekdayNumber = 7; } Weekday weekday = (Weekday)weekdayNumber; // check for a valid value weekday.Number(); return(weekday); }
public void Test_Number_Ok(Weekday weekday, int expectedNumber) { Assert.Equal(expectedNumber, weekday.Number()); }
private static string FormatWeekday(this Weekday weekday, string format, CultureInfo culture) { // use an arbitrary DateTime with the specified weekday and format it only with the full name of the weekday // -> start with a Sunday and add the specfied weekday value DateTime dateTime = new DateTime(2019, Month.November.Number(), 3).AddDays(weekday.Number()); return(dateTime.ToString(format, culture)); }