blob: b5a9c8206b76004ff61f40cd15d7e8054f18f3da (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include "Period.hpp"
#include "openvic-simulation/utility/Logger.hpp"
using namespace OpenVic;
Period::Period(
Date new_start_date,
std::optional<Date> new_end_date
) : start_date { new_start_date }, end_date { new_end_date } {}
bool Period::is_date_in_period(Date date) const {
return start_date <= date && (!end_date.has_value() || end_date.value() >= date);
}
bool Period::try_set_end(Date date) {
if (end_date.has_value()) {
Logger::error("Period already has end date ", end_date.value());
return false;
}
if (date < start_date) {
Logger::error("Proposed end date ", date, " is before start date ", start_date);
return false;
}
end_date = date;
return true;
}
|