using System; using System.Globalization; namespace NzbDrone.Common { public static class DateTimeExtensions { public static DateTime GetFirstDayOfWeek(this DateTime dayInWeek) { var defaultCultureInfo = CultureInfo.CurrentCulture; return GetFirstDayOfWeek(dayInWeek, defaultCultureInfo); } public static DateTime GetFirstDayOfWeek(this DateTime dayInWeek, CultureInfo cultureInfo) { DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek; DateTime firstDayInWeek = dayInWeek.Date; while (firstDayInWeek.DayOfWeek != firstDay) firstDayInWeek = firstDayInWeek.AddDays(-1); return firstDayInWeek; } } }