using System;

namespace DataClasses
{
    public static class DateTimeExtensions
    {
        public static DateTime StartOfWeek(this DateTime dt, DayOfWeekEnum startOfWeek)
        {
            int diff = (int)Enum.Parse(typeof(DayOfWeekEnum),dt.DayOfWeek.ToString()) - (int)startOfWeek;
            if (diff < 0)
            {
                diff += 7;
            }

            return dt.AddDays(-1 * diff).Date;
        }

        public static DateTime EndOfWeek(this DateTime dt, DayOfWeekEnum endOfWeek)
        {
            int diff = (int)endOfWeek - (int)Enum.Parse(typeof(DayOfWeekEnum), dt.DayOfWeek.ToString());

            return dt.AddDays(diff).Date;
        }
    }
}
