示例#1
0
 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");
     }
 }
示例#2
0
 public static DateTime From(this MonthUnit months, DateTime dateTime)
 {
     return(dateTime + months);
 }
示例#3
0
 public static DateTime Before(this MonthUnit months, DateTime dateTime)
 {
     return(dateTime - months);
 }
示例#4
0
 public static DateTime FromNow(this MonthUnit months)
 {
     return(DateTime.Today + months);
 }
示例#5
0
 public static DateTime Ago(this MonthUnit months)
 {
     return(DateTime.Today - months);
 }