/// <summary>Gets the number of business days in between, i.e. the number of business days in ]<paramref name="date1"/>, <paramref name="date2"/>] /// or ]<paramref name="date2"/>, <paramref name="date1"/>] <c>without</c> taking into account any business day convention. /// </summary> /// <param name="date1">The first date.</param> /// <param name="date2">The second date.</param> /// <returns> /// The number of business days between <paramref name="date1"/> and <paramref name="date2"/> including the latest date if this is a business day. /// </returns> /// <exception cref="ArgumentException">Thrown, if for <paramref name="date1"/> or <paramref name="date2"/>the current /// calendar is not defined, i.e. <paramref name="date1"/> or <paramref name="date2"/> is less than <see cref="FirstDate"/> /// or greater than <see cref="LastDate"/>.</exception> public int GetNumberOfBusinessDaysInBetween(DateTime date1, DateTime date2) { if (date2 < date1) { DateTime tempDateTime = date1; date1 = date2; date2 = tempDateTime; } if ((date1 < FirstDate) || (date2 > LastDate)) { throw new ArgumentException("The holiday calendar " + Name.ToString() + " causes a fatal error. The date " + date1.ToString("d") + " or " + date2.ToString("d") + " lies not between the earliest date " + FirstDate.ToString("d") + " and the latest date " + LastDate.ToString("d") + " for which holiday informations are available."); } int numberOfBusinessDaysInBetween = 0; /* if the time difference is small, i.e. one week, we call 'IsBusinessDay', otherwise we take * into account the number of weekend days first and add the number of public holidays later: */ if (date2.Subtract(date1).Days <= 7) { // for example: friday -> monday, saturday -> monday, in any other case +1 day: DateTime date = m_WeekendRepresentation.GetNextWorkingDay(date1); while (date <= date2) { if (IsBusinessDayForNonWeekendDay(date)) { numberOfBusinessDaysInBetween++; } // again: friday -> monday, saturday -> monday, in any other case +1 day: date = m_WeekendRepresentation.GetNextWorkingDay(date); } return(numberOfBusinessDaysInBetween); } /* count the number of days != Saturdays and Sundays [for a 'standard' weekend] first: */ numberOfBusinessDaysInBetween = m_WeekendRepresentation.GetNumberOfWorkingDaysInBetween(date1, date2); return(numberOfBusinessDaysInBetween - GetNumberOfNonWeekendHolidaysInBetween(date1, date2)); }
/// <summary> /// Returns a identifier with small letter as start /// </summary> /// <param name="name"></param> /// <returns></returns> protected string StartWithSmallLetter(IdentifierString name) { return(name.ToString().Substring(0, 1).ToLowerInvariant() + name.ToString().Substring(1)); }