private static int RemoveWeekends(DateTime start_date, DateTime end_date, int res) { int num = ((int)(end_date.ToOADate() - start_date.ToOADate())) % 7; CalcWeekDayFunction function = new CalcWeekDayFunction(); int num2 = ((int)function.Evaluate(new object[] { start_date, (int)2 })) + num; num = (num2 > 5) ? (num2 - 5) : 0; int num3 = (start_date.DayOfWeek == DayOfWeek.Sunday) ? 1 : 2; num = (num > num3) ? num3 : num; res -= num; int num4 = (res / 7) * 2; res -= num4; return(res); }
/// <summary> /// Returns a number that represents a date that is the indicated number of /// working days before or after a date (the starting date). /// </summary> /// <param name="args"><para> /// The args contains 2 - 3 items: start_date, days, [holidays]. /// </para> /// <para> /// Start_date is a date that represents the start date. /// </para> /// <para> /// Days is the number of nonweekend and nonholiday days before or after start_date. /// A positive value for days yields a future date; a negative value yields a past date. /// </para> /// <para> /// [Holidays] is an optional list of one or more dates to exclude from the working calendar, /// such as state and federal holidays and floating holidays. /// The list can be either a range of cells that contain the dates or an /// array constant (array: Used to build single formulas that produce multiple /// results or that operate on a group of arguments that are arranged in rows and columns. /// An array range shares a common formula; an array constant is a group of constants /// used as an argument.) of the serial numbers that represent the dates. /// </para></param> /// <returns> /// A <see cref="T:System.Double" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); DateTime item = CalcConvert.ToDateTime(args[0]); int num = CalcConvert.ToInt(args[1]); int num2 = CalcHelper.ArgumentExists(args, 2) ? ArrayHelper.GetLength(args[2], 0) : 0; List <DateTime> list = new List <DateTime>(); for (int i = 0; i < num2; i++) { list.Add(CalcConvert.ToDateTime(ArrayHelper.GetValue(args[2], i, 0))); } object obj2 = new CalcWeekDayFunction().Evaluate(new object[] { item, (int)3 }); if (obj2 is CalcError) { return(obj2); } int num4 = CalcConvert.ToInt(obj2); while (num < 0) { try { item = item.AddDays(-1.0); } catch { return(CalcErrors.Number); } if (num4 == 0) { num4 = 6; } else { num4--; } if ((num4 == 5) || (num4 == 6)) { num--; } else if (list.Contains(item)) { num--; } num++; } while (num > 0) { try { item = item.AddDays(1.0); } catch { return(CalcErrors.Number); } if (num4 == 6) { num4 = 0; } else { num4++; } if ((num4 == 5) || (num4 == 6)) { num++; } else if (list.Contains(item)) { num++; } num--; } return((double)item.ToOADate()); }