private List <TimeInterval> CalculatePeriods(DateTime start, double hours) { var end = start; while (hours > 0) { var hoursHolder = hours; var increHours = Math.Min(hours, 1); double hoursOffset; var nextWorkingTime = NextWorkingTime(end, false, out hoursOffset); if (double.IsNaN(hoursOffset)) { hours -= increHours; end = end.AddHours(increHours); } else { hours += hoursOffset; var h = end; end = end.AddHours(-hoursOffset); if (h > end) { throw new Exception("NOt"); } if (end < start) { throw new Exception("NOt"); } Breaks.Add(new TimeInterval(start, end)); start = nextWorkingTime; end = nextWorkingTime; } if (hours == 0) { if (end < start) { throw new Exception("NOt"); } Breaks.Add(new TimeInterval(start, end)); } } return(this.Breaks); }
private DateTime AddDays(DateTime start, double hours, bool isStart) { while (hours > 0) { if (hours > 1) { start = start.AddHours(1); start = NextWorkingTime(start, false); hours -= 1.0; } else { start = start.AddHours(hours); if (start.TimeOfDay >= TimeSpan.FromHours(isStart ? 17 : 17.01)) { TimeSpan duration = start.TimeOfDay - TimeSpan.FromHours(17); start = NextWorkingTime(start, isStart).Add(duration); } hours = 0; } } start = NextWorkingTime(start, isStart); return(start); }