25#include <ql/time/calendar.hpp>
26#include <ql/errors.hpp>
34 const Date& from,
const Date& to,
35 bool includeFirst,
bool includeLast) {
37 for (Date d = includeFirst ? from : from + 1; d < to; ++d) {
46 QL_REQUIRE(
impl_,
"no calendar implementation provided");
48#ifdef QL_HIGH_RESOLUTION_DATE
49 const Date _d(d.dayOfMonth(), d.month(), d.year());
55 impl_->removedHolidays.erase(_d);
58 if (
impl_->isBusinessDay(_d))
59 impl_->addedHolidays.insert(_d);
63 QL_REQUIRE(
impl_,
"no calendar implementation provided");
65#ifdef QL_HIGH_RESOLUTION_DATE
66 const Date _d(d.dayOfMonth(), d.month(), d.year());
72 impl_->addedHolidays.erase(_d);
75 if (!
impl_->isBusinessDay(_d))
76 impl_->removedHolidays.insert(_d);
80 impl_->addedHolidays.clear();
81 impl_->removedHolidays.clear();
86 QL_REQUIRE(d !=
Date(),
"null date");
98 if (d1.
month() != d.month()) {
102 if (d.dayOfMonth() <= 15 && d1.
dayOfMonth() > 15) {
125 QL_FAIL(
"unknown business-day convention");
133 bool endOfMonth)
const {
134 QL_REQUIRE(d!=
Date(),
"null date");
137 }
else if (unit ==
Days) {
155 }
else if (unit ==
Weeks) {
156 Date d1 = d + n*unit;
159 Date d1 = d + n*unit;
172 bool endOfMonth)
const {
179 bool includeLast)
const {
180 return (from < to) ? daysBetweenImpl(*
this, from, to, includeFirst, includeLast) :
181 (from > to) ? -daysBetweenImpl(*
this, to, from, includeLast, includeFirst) :
194 static const Day EasterMonday[] = {
195 98, 90, 103, 95, 114, 106, 91, 111, 102,
196 87, 107, 99, 83, 103, 95, 115, 99, 91, 111,
197 96, 87, 107, 92, 112, 103, 95, 108, 100, 91,
198 111, 96, 88, 107, 92, 112, 104, 88, 108, 100,
199 85, 104, 96, 116, 101, 92, 112, 97, 89, 108,
200 100, 85, 105, 96, 109, 101, 93, 112, 97, 89,
201 109, 93, 113, 105, 90, 109, 101, 86, 106, 97,
202 89, 102, 94, 113, 105, 90, 110, 101, 86, 106,
203 98, 110, 102, 94, 114, 98, 90, 110, 95, 86,
204 106, 91, 111, 102, 94, 107, 99, 90, 103, 95,
205 115, 106, 91, 111, 103, 87, 107, 99, 84, 103,
206 95, 115, 100, 91, 111, 96, 88, 107, 92, 112,
207 104, 95, 108, 100, 92, 111, 96, 88, 108, 92,
208 112, 104, 89, 108, 100, 85, 105, 96, 116, 101,
209 93, 112, 97, 89, 109, 100, 85, 105, 97, 109,
210 101, 93, 113, 97, 89, 109, 94, 113, 105, 90,
211 110, 101, 86, 106, 98, 89, 102, 94, 114, 105,
212 90, 110, 102, 86, 106, 98, 111, 102, 94, 114,
213 99, 90, 110, 95, 87, 106, 91, 111, 103, 94,
214 107, 99, 91, 103, 95, 115, 107, 91, 111, 103,
215 88, 108, 100, 85, 105, 96, 109, 101, 93, 112,
216 97, 89, 109, 93, 113, 105, 90, 109, 101, 86,
217 106, 97, 89, 102, 94, 113, 105, 90, 110, 101,
218 86, 106, 98, 110, 102, 94, 114, 98, 90, 110,
219 95, 86, 106, 91, 111, 102, 94, 107, 99, 90,
220 103, 95, 115, 106, 91, 111, 103, 87, 107, 99,
221 84, 103, 95, 115, 100, 91, 111, 96, 88, 107,
222 92, 112, 104, 95, 108, 100, 92, 111, 96, 88,
223 108, 92, 112, 104, 89, 108, 100, 85, 105, 96,
224 116, 101, 93, 112, 97, 89, 109, 100, 85, 105
226 return EasterMonday[y-1901];
236 static const Day EasterMonday[] = {
237 105, 118, 110, 102, 121, 106, 126, 118, 102,
238 122, 114, 99, 118, 110, 95, 115, 106, 126, 111,
239 103, 122, 107, 99, 119, 110, 123, 115, 107, 126,
240 111, 103, 123, 107, 99, 119, 104, 123, 115, 100,
241 120, 111, 96, 116, 108, 127, 112, 104, 124, 115,
242 100, 120, 112, 96, 116, 108, 128, 112, 104, 124,
243 109, 100, 120, 105, 125, 116, 101, 121, 113, 104,
244 117, 109, 101, 120, 105, 125, 117, 101, 121, 113,
245 98, 117, 109, 129, 114, 105, 125, 110, 102, 121,
246 106, 98, 118, 109, 122, 114, 106, 118, 110, 102,
247 122, 106, 126, 118, 103, 122, 114, 99, 119, 110,
248 95, 115, 107, 126, 111, 103, 123, 107, 99, 119,
249 111, 123, 115, 107, 127, 111, 103, 123, 108, 99,
250 119, 104, 124, 115, 100, 120, 112, 96, 116, 108,
251 128, 112, 104, 124, 116, 100, 120, 112, 97, 116,
252 108, 128, 113, 104, 124, 109, 101, 120, 105, 125,
253 117, 101, 121, 113, 105, 117, 109, 101, 121, 105,
254 125, 110, 102, 121, 113, 98, 118, 109, 129, 114,
255 106, 125, 110, 102, 122, 106, 98, 118, 110, 122,
256 114, 99, 119, 110, 102, 115, 107, 126, 118, 103,
257 123, 115, 100, 120, 112, 96, 116, 108, 128, 112,
258 104, 124, 109, 100, 120, 105, 125, 116, 108, 121,
259 113, 104, 124, 109, 101, 120, 105, 125, 117, 101,
260 121, 113, 98, 117, 109, 129, 114, 105, 125, 110,
261 102, 121, 113, 98, 118, 109, 129, 114, 106, 125,
262 110, 102, 122, 106, 126, 118, 103, 122, 114, 99,
263 119, 110, 102, 115, 107, 126, 111, 103, 123, 114,
264 99, 119, 111, 130, 115, 107, 127, 111, 103, 123,
265 108, 99, 119, 104, 124, 115, 100, 120, 112, 103,
266 116, 108, 128, 119, 104, 124, 116, 100, 120, 112
268 return EasterMonday[y-1901];
272 const Date& from,
const Date& to,
bool includeWeekEnds)
const {
274 QL_REQUIRE(to>=from,
"'from' date ("
275 << from <<
") must be equal to or earlier than 'to' date ("
277 std::vector<Date> result;
278 for (
Date d = from; d <= to; ++d) {
286 const Date& from,
const Date& to)
const {
288 QL_REQUIRE(to>=from,
"'from' date ("
289 << from <<
") must be equal to or earlier than 'to' date ("
291 std::vector<Date> result;
292 for (
Date d = from; d <= to; ++d) {
static Day easterMonday(Year)
expressed relative to first day of year
bool isWeekend(Weekday) const override
static Day easterMonday(Year)
expressed relative to first day of year
bool isWeekend(Weekday) const override
bool isWeekend(Weekday w) const
Date::serial_type businessDaysBetween(const Date &from, const Date &to, bool includeFirst=true, bool includeLast=false) const
void removeHoliday(const Date &)
bool isEndOfMonth(const Date &d) const
bool isBusinessDay(const Date &d) const
void addHoliday(const Date &)
Date adjust(const Date &, BusinessDayConvention convention=Following) const
std::vector< Date > holidayList(const Date &from, const Date &to, bool includeWeekEnds=false) const
bool isHoliday(const Date &d) const
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
ext::shared_ptr< Impl > impl_
void resetAddedAndRemovedHolidays()
std::vector< Date > businessDayList(const Date &from, const Date &to) const
Date endOfMonth(const Date &d) const
last business day of the month to which the given date belongs
std::int_fast32_t serial_type
serial number type
TimeUnit
Units used to describe time periods.
BusinessDayConvention
Business Day conventions.
@ HalfMonthModifiedFollowing
QL_INTEGER Integer
integer number