/// <summary> /// Get a DateTime representing the current unit of time. /// </summary> /// <param name="current">The current date.</param> /// <param name="dateUnit">The date unit.</param> /// <returns></returns> public static DateTime This(this DateTime current, DateUnit dateUnit) { switch (dateUnit) { case DateUnit.Day: return current.Midnight(); case DateUnit.Week: return current.AddWeeks(-1).Next(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); case DateUnit.Month: return current.First(); case DateUnit.Year: return new DateTime(current.Year,1,1); } return current; }
/// <summary> /// Adds one week to the specified <see cref="DateTime">DateTime</see> value. /// </summary> /// <param name="value">The date to evaluate.</param> /// <returns>A <see cref="DateTime">DateTime</see> representing one weeek after the specified <see cref="DateTime">DateTime</see>.</returns> public static DateTime AddWeek(this DateTime value) { return value.AddWeeks(1); }
/// <summary> /// Subtracts given weeks from the given DateTime. /// </summary> /// <param name="date">The given DateTime.</param> /// <param name="weeks">Number of weeks to be subtracted.</param> /// <returns>The DateTime after the given weeks are subtracted.</returns> public static DateTime SubtractWeeks(this DateTime date, int weeks) { return date.AddWeeks(weeks.Negate()); }
/// <summary> /// Adds one week to the given DateTime. /// </summary> /// <param name="date">The given DateTime.</param> /// <returns>The DateTime after one week is added.</returns> public static DateTime AddAWeek(this DateTime date) { return date.AddWeeks(1); }
public static DateTime SubtractWeeks(this DateTime dateTime, int weeks) { return dateTime.AddWeeks(-weeks); }
public static DateTime SubtractWeeks(this DateTime date, double value) { if (value < 0) throw new ArgumentException("Value cannot be less than 0.", "value"); return date.AddWeeks(value * -1); }
public static DateTime AddWeek(this DateTime d) { return d.AddWeeks(1); }
public static DateTimeOffset SubtractWeeks(this DateTimeOffset dateTimeOffset, double weeks) { return dateTimeOffset.AddWeeks(-weeks); }
public static DateTime? GetDayOfWeekInTheMonth(this DateTime date, DayOfWeek dayOfWeek, int instance) { if (instance <= 0) return null; date = FirstDayOfTheMonth(date, dayOfWeek); if (instance == 1) return date; return date.AddWeeks(); }