public static IEnumerable <DateTime> StepTo(this DateTime from, DateTime to, DayUnit step) { if (step.Days > 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.Days < 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 DayUnit days, DateTime dateTime) { return(dateTime + days); }
public static DateTime Before(this DayUnit days, DateTime dateTime) { return(dateTime - days); }
public static DateTime FromNow(this DayUnit days) { return(DateTime.Today + days); }
public static DateTime Ago(this DayUnit days) { return(DateTime.Today - days); }