dateTime calendar::adjust(const dateTime& d, businessDayConvention c) const { //QL_REQUIRE(d != Date(), "null date"); if (c == unadjusted) return d; dateTime d1 = d; if (c == following || c == modifiedFollowing) { while (!isBusinessDay(d1)) d1 + boost::gregorian::days(1); if (c == modifiedFollowing) { if (d1.month() != d.month()) return adjust(d, preceding); } } else if (c == preceding || c == modifiedPreceding) { while (!isBusinessDay(d1)) d1 - boost::gregorian::days(1); if (c == modifiedPreceding && d1.month() != d.month()) return adjust(d, following); } else { //QL_FAIL("unknown business-day convention"); } return d1; }
BigInteger Calendar::businessDaysBetween(const Date& from, const Date& to, bool includeFirst, bool includeLast) const { BigInteger wd = 0; if (from != to) { if (from < to) { // the last one is treated separately to avoid // incrementing Date::maxDate() for (Date d = from; d < to; ++d) { if (isBusinessDay(d)) ++wd; } if (isBusinessDay(to)) ++wd; } else if (from > to) { for (Date d = to; d < from; ++d) { if (isBusinessDay(d)) ++wd; } if (isBusinessDay(from)) ++wd; } if (isBusinessDay(from) && !includeFirst) wd--; if (isBusinessDay(to) && !includeLast) wd--; if (from > to) wd = -wd; } return wd; }
inline bool Calendar::isHoliday(const Date& d) const { return !isBusinessDay(d); }