コード例 #1
0
 /// <summary>
 /// Add an interval of time (or some multiple thereof) to a DateTime.
 /// </summary>
 public static DateTime AddInterval(this DateTime dt, Time.IntervalType interval, int numberOfIntervals)
 {
     if (interval == Time.IntervalType.Day)
         return dt.AddDays(numberOfIntervals);
     else if (interval == Time.IntervalType.Week)
         return dt.AddDays(7 * numberOfIntervals);
     else if (interval == Time.IntervalType.Month)
         return dt.AddMonths(numberOfIntervals);
     else if (interval == Time.IntervalType.Quarter) // won't necessarily work for qtr end dates
         return dt.AddMonths(3 * numberOfIntervals);
     else if (interval == Time.IntervalType.Year)
         return dt.AddYears(numberOfIntervals);
     else
         return dt;
 }
コード例 #2
0
 /// <summary>
 /// Maps a function to a timeline, starting on a given date.
 /// </summary>
 //  TODO: Get rid of Time.IntervalType
 public static Tnum TemporalMap(Func<Tnum,Tnum> fcn, Tdate startDate, Tnum intervalCount, Time.IntervalType intervalType)
 {
     return fcn(Time.IntervalsSince(startDate, startDate.AddYears(intervalCount), intervalType));
 }
コード例 #3
0
 /// <summary>
 /// Subtract an interval of time from a DateTime.
 /// </summary>
 public static DateTime SubtractInterval(this DateTime dt, Time.IntervalType interval)
 {
     if (interval == Time.IntervalType.Day)
         return dt.AddDays(-1);
     else if (interval == Time.IntervalType.Week)
         return dt.AddDays(-7);
     else if (interval == Time.IntervalType.Month)  // not reversible version of AddInterval
         return dt.AddMonths(-1);
     else if (interval == Time.IntervalType.Quarter) // won't necessarily work for qtr end dates
         return dt.AddMonths(-3);
     else if (interval == Time.IntervalType.Year)
         return dt.AddYears(-1);
     else
         return dt;
 }