aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/Period.cpp
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-01-07 13:49:20 +0100
committer wvpm <24685035+wvpm@users.noreply.github.com>2024-01-07 14:57:40 +0100
commitddbb6af66e30e896f07a39503a1bb935e462c095 (patch)
treeaf1d3ab4924675e14a24483dea9b012e235bf5ec /src/openvic-simulation/history/Period.cpp
parent199a1b7915f4c431e733cfe037608f1310972cb4 (diff)
Reparations & optional end date
Diffstat (limited to 'src/openvic-simulation/history/Period.cpp')
-rw-r--r--src/openvic-simulation/history/Period.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/openvic-simulation/history/Period.cpp b/src/openvic-simulation/history/Period.cpp
new file mode 100644
index 0000000..cb133dd
--- /dev/null
+++ b/src/openvic-simulation/history/Period.cpp
@@ -0,0 +1,27 @@
+#include "openvic-simulation/history/Period.hpp"
+
+using namespace OpenVic;
+
+Period::Period(
+ const Date new_start_date,
+ const std::optional<Date> new_end_date
+) : start_date {new_start_date}, end_date {new_end_date} {}
+
+bool Period::is_date_in_period(const Date date) const {
+ return start_date <= date && (!end_date.has_value() || end_date.value() >= date);
+}
+
+bool Period::try_set_end(const 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;
+} \ No newline at end of file