public static IEnumerable <DateTime> StepTo(this DateTime from, DateTime to, MonthUnit step) { if (step.Months > 0L) { var limit = (DateTime.MaxValue - step).AddTicks(1L); if (limit > to) { limit = to; } for (; from < limit; from += step) { yield return(from); } if (from <= to) { yield return(from); } } else if (step.Months < 0L) { var limit = (DateTime.MinValue - step).AddTicks(-1L); if (limit < to) { limit = to; } for (; from > limit; from += step) { yield return(from); } if (from >= to) { yield return(from); } } else { throw new ArgumentException("step cannot be zero"); } }
public static DateTime From(this MonthUnit months, DateTime dateTime) { return(dateTime + months); }
public static DateTime Before(this MonthUnit months, DateTime dateTime) { return(dateTime - months); }
public static DateTime FromNow(this MonthUnit months) { return(DateTime.Today + months); }
public static DateTime Ago(this MonthUnit months) { return(DateTime.Today - months); }