28 typedef std::map<Year, std::map<Month, Date::serial_type> > Cache;
29 typedef std::map<Year, Date::serial_type> OuterCache;
31 std::map<std::string, Cache> monthlyFigures_;
32 std::map<std::string, OuterCache> yearlyFigures_;
34 bool sameYear(
const Date& d1,
const Date& d2) {
35 return d1.year() == d2.year();
38 bool sameMonth(
const Date& d1,
const Date& d2) {
39 return d1.year() == d2.year() && d1.month() == d2.month();
43 const Calendar& calendar,
45 if (cache[year][month] == 0) {
47 Date d1 = Date(1,month,year);
49 cache[year][month] = calendar.businessDaysBetween(d1, d2);
51 return cache[year][month];
56 const Calendar& calendar,
58 if (outerCache[year] == 0) {
62 total += businessDays(cache,calendar,
65 outerCache[year] = total;
67 return outerCache[year];
73 std::ostringstream out;
79 const Date& d2)
const {
80 if (sameMonth(d1,d2) || d1 >= d2) {
85 return calendar_.businessDaysBetween(d1, d2);
86 }
else if (sameYear(d1,d2)) {
87 Cache& cache = monthlyFigures_[calendar_.name()];
92 total += calendar_.businessDaysBetween(d1,
d);
95 while (!sameMonth(
d,d2)) {
96 total += businessDays(cache, calendar_,
101 total += calendar_.businessDaysBetween(
d, d2);
104 Cache& cache = monthlyFigures_[calendar_.name()];
105 OuterCache& outerCache = yearlyFigures_[calendar_.name()];
111 total += calendar_.businessDaysBetween(d1,
d);
114 total += businessDays(cache, calendar_,
119 while (!sameYear(
d,d2)) {
120 total += businessDays(outerCache, cache,
121 calendar_,
d.year());
127 total += businessDays(cache, calendar_,
132 total += calendar_.businessDaysBetween(
d, d2);
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Time yearFraction(const Date &d1, const Date &d2, const Date &, const Date &) const override
std::string name() const override
std::string name() const
Returns the name of the calendar.
std::int_fast32_t serial_type
serial number type
Date::serial_type dayCount(const Date &, const Date &) const
Returns the number of days between two dates.
Real Time
continuous quantity with 1-year units
QL_INTEGER Integer
integer number