public static DateTime ToStartOfWeek(this DateTime dateTime) { var dayOfWeek = julianCalendar.GetDayOfWeek(dateTime); var start = dateTime.Subtract(TimeSpan.FromDays((int)dayOfWeek)); return(start.ToStartOfDay()); }
public void DateTimeExt_TestEndOfWeek() { var current = DateTime.UtcNow; var processed = current.ToEndOfWeek(); Assert.AreEqual(DayOfWeek.Saturday, julian.GetDayOfWeek(processed)); Assert.IsTrue(julian.GetDayOfYear(current) <= julian.GetDayOfYear(processed)); }