/// <summary> /// Add a value of time units to dateTime by calendar information. /// </summary> /// <param name="dateTime">Calendar time.</param> /// <param name="timeUnit">Time unit.</param> /// <param name="value">Value.</param> /// <returns>Calendar time.</returns> public DateTime Add(DateTime dateTime, int value) { if (value <= 0) { return(dateTime); } IEnumerable <ICalendarDay> days = _calendar.GetDays(_countTerm, dateTime, value); return(_countTerm.Calculate(days, value)); }
/// <summary> /// Gets the time units. /// </summary> /// <param name="calendar">The calendar.</param> /// <param name="periods">The periods.</param> /// <returns>Time units count.</returns> public override int GetTimeUnits(ICalendar <ICalendarDay> calendar, IEnumerable <DateTimeInterval> periods) { var result = 0; foreach (var p in periods) { var days = calendar.GetDays(this, p.Start, p.End); var lastDay = days.FirstOrDefault(day => !day.IsNonWorking); var endOfWorkingDayTime = lastDay.WorkingIntervals.Max(wi => wi.End); result += p.End.TimeOfDay < endOfWorkingDayTime ? 0 : 1; } return(result); }
/// <summary> /// Gets amount of time units of all given time periods by calendar. /// </summary> /// <param name="calendar">The calendar.</param> /// <param name="periods">The periods.</param> /// <returns>Time units amount.</returns> public override int GetTimeUnits(ICalendar <ICalendarDay> calendar, IEnumerable <DateTimeInterval> periods) { return(periods.Aggregate(0, (acc, period) => acc + GetTimeUnits(calendar.GetDays(this, period.Start, period.End), period.End))); }
/// <summary> /// Gets actualized days. /// </summary> /// <param name="calendar">The calendar.</param> /// <param name="countTerm">The count term.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <returns>Actualized calendar days collection.</returns> public static IEnumerable <ICalendarDay> GetDays(this ICalendar <ICalendarDay> calendar, BaseCountTerm countTerm, DateTime start, DateTime end) { return(calendar.GetDays(countTerm, start, (end - start).Days + 1)); }