/// <summary> /// Returns the end of week from the supplied date /// </summary> public static DateTime EndOfWeek(this DateTime instance, DayOfWeek? on = null) { DayOfWeek day = on.GetValueOrDefault(DayOfWeek.Saturday); int days = day - instance.DayOfWeek; if (days < 0) days += 7; days = days * -1; return new DateTime(instance.Year, instance.Month, instance.Day, 23, 59, 59, 999).AddDays(days); }
/// <summary> /// Returns the start of week from the supplied date /// </summary> public static DateTime StartOfWeek(this DateTime instance, DayOfWeek? on = null) { DayOfWeek day = on.GetValueOrDefault(DayOfWeek.Sunday); int days = instance.DayOfWeek - day; if (days < 0) days += 7; days = days * -1; return new DateTime(instance.Year, instance.Month, instance.Day, 0, 0, 0, 0).AddDays(days); }
/// <summary> /// <paramref name="weekRule"/>, <paramref name="firstDayOfWeek"/>에 해당하는 <see cref="WeekOfYearRuleKind"/>를 판단합니다. /// </summary> /// <param name="weekRule">한해의 첫주를 산정하는 규칙</param> /// <param name="firstDayOfWeek">한주의 첫번째 요일</param> public static WeekOfYearRuleKind GetWeekOfYearRuleKind(CalendarWeekRule? weekRule = null, DayOfWeek? firstDayOfWeek = null) { if(weekRule.GetValueOrDefault(DateTimeFormatInfo.CurrentInfo.CalendarWeekRule) == CalendarWeekRule.FirstFourDayWeek && firstDayOfWeek.GetValueOrDefault(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) == DayOfWeek.Monday) return WeekOfYearRuleKind.Iso8601; return WeekOfYearRuleKind.Calendar; }