QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
dateinterval.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 J. Erik Radmall
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24#ifndef quantlib_date_interval_hpp
25#define quantlib_date_interval_hpp
26
27#include <ql/time/date.hpp>
28#include <ql/errors.hpp>
29#include <algorithm>
30
31namespace QuantLib {
32
34
36 friend std::ostream& operator<<(std::ostream&, const DateInterval&);
37
38 private:
41 public:
42 DateInterval() = default;
45 QL_REQUIRE(endDate_ >= startDate_,
46 "end date must be >= start date");
47 }
48 const Date& startDate() const { return startDate_; }
49 const Date& endDate() const { return endDate_; }
50
52 bool includeFirst = true,
53 bool includeLast = true) const {
54 if (includeFirst && !(date >= startDate_))
55 return false;
56 else if (!(date > startDate_))
57 return false;
58 if (includeLast && !(date <= endDate_))
59 return false;
60 else if (!(date < endDate_))
61 return false;
62 return true;
63 }
64
66 if ((startDate_ < di.startDate_ && endDate_ < di.startDate_) ||
67 (startDate_ > di.endDate_ && endDate_ > di.endDate_))
68 return {};
69 return {std::max(startDate_, di.startDate_), std::min(endDate_, di.endDate_)};
70 }
71
72 bool operator==(const DateInterval& rhs) const {
73 return startDate_ == rhs.startDate_ && endDate_ == rhs.endDate_;
74 }
75
76 bool operator!=(const DateInterval& rhs) const {
77 return !(*this == rhs);
78 }
79 };
80
81}
82
83#endif
Concrete date class.
Definition: date.hpp:125
Date interval described by a number of a given time unit.
const Date & endDate() const
DateInterval intersection(const DateInterval &di) const
bool isDateBetween(Date date, bool includeFirst=true, bool includeLast=true) const
bool operator!=(const DateInterval &rhs) const
bool operator==(const DateInterval &rhs) const
const Date & startDate() const
DateInterval(const Date &startDate, const Date &endDate)
friend std::ostream & operator<<(std::ostream &, const DateInterval &)
Definition: any.hpp:35