private static void SumIfHasFlag(ref int count, WeekDay weekDay, DayOfWeek dayToCheck) { if (weekDay.HasFlag(Convert(dayToCheck))) { count++; } }
private bool IsToday(WeekDay day) { switch (DateTime.Now.DayOfWeek) { default: return(false); case DayOfWeek.Sunday: return(day.HasFlag(WeekDay.Sunday)); case DayOfWeek.Monday: return(day.HasFlag(WeekDay.Monday)); case DayOfWeek.Tuesday: return(day.HasFlag(WeekDay.Tuesday)); case DayOfWeek.Wednesday: return(day.HasFlag(WeekDay.Wednesday)); case DayOfWeek.Thursday: return(day.HasFlag(WeekDay.Thursday)); case DayOfWeek.Friday: return(day.HasFlag(WeekDay.Friday)); case DayOfWeek.Saturday: return(day.HasFlag(WeekDay.Saturday)); } }
public static bool SameDay(WeekDay weekDay, DayOfWeek dayOfWeek) { switch (dayOfWeek) { default: return(false); case DayOfWeek.Sunday: return(weekDay.HasFlag(WeekDay.Sunday)); case DayOfWeek.Monday: return(weekDay.HasFlag(WeekDay.Monday)); case DayOfWeek.Tuesday: return(weekDay.HasFlag(WeekDay.Tuesday)); case DayOfWeek.Wednesday: return(weekDay.HasFlag(WeekDay.Wednesday)); case DayOfWeek.Thursday: return(weekDay.HasFlag(WeekDay.Thursday)); case DayOfWeek.Friday: return(weekDay.HasFlag(WeekDay.Friday)); case DayOfWeek.Saturday: return(weekDay.HasFlag(WeekDay.Saturday)); } }
private static void SumIfHasFlags(ref int count, WeekDay weekDay, int toSum, params WeekDay[] daysToCheck) { foreach (var dayToCheck in daysToCheck) { if (weekDay.HasFlag(dayToCheck)) { count += toSum; } } }
public static DateTime NextDateTimeOn(this DateTime from, WeekDay toDays, TimeSpan toTime) { var weekDay = from.DayOfWeek.ToWeekDay(); var hasToday = toDays.HasFlag(weekDay); if (hasToday && from.TimeOfDay <= toTime) { return(from.Date + toTime); } if (!hasToday || toDays != weekDay) { do { weekDay = weekDay.Next <WeekDay>(); }while (!toDays.HasFlag(weekDay)); } return(from.ToNextDayOfWeek(weekDay.ToDayOfWeek(), true).Date + toTime); }
private static string ToRfc5545String(WeekDay weekDay) { return(string.Join(",", WeekDayMap.Where(kv => weekDay.HasFlag(kv.Key)).Select(kv => kv.Value))); }