コード例 #1
0
ファイル: DateTimeExt.cs プロジェクト: chaowlert/algorithm
 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
ファイル: DateTimeExt.cs プロジェクト: chaowlert/algorithm
 public static DateTime From(this MonthUnit months, DateTime dateTime)
 {
     return(dateTime + months);
 }
コード例 #3
0
ファイル: DateTimeExt.cs プロジェクト: chaowlert/algorithm
 public static DateTime Before(this MonthUnit months, DateTime dateTime)
 {
     return(dateTime - months);
 }
コード例 #4
0
ファイル: DateTimeExt.cs プロジェクト: chaowlert/algorithm
 public static DateTime FromNow(this MonthUnit months)
 {
     return(DateTime.Today + months);
 }
コード例 #5
0
ファイル: DateTimeExt.cs プロジェクト: chaowlert/algorithm
 public static DateTime Ago(this MonthUnit months)
 {
     return(DateTime.Today - months);
 }