aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types/Date.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-12-02 20:42:06 +0100
committer GitHub <noreply@github.com>2023-12-02 20:42:06 +0100
commit444a27726695478e44e0166e75df1f354b6432d5 (patch)
treef1f6276c91beceecdfd9b09083d1c91ea8b41b60 /src/openvic-simulation/types/Date.cpp
parentcd6875d5e0ca5e2545fd0e1647678cd18a6c81c2 (diff)
parent4a899c1a9e83ab9476b85522751081be434caa35 (diff)
Merge pull request #82 from OpenVicProject/backlog
Accumulated changes from Dev Diary GUI focus period
Diffstat (limited to 'src/openvic-simulation/types/Date.cpp')
-rw-r--r--src/openvic-simulation/types/Date.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/openvic-simulation/types/Date.cpp b/src/openvic-simulation/types/Date.cpp
index 1b15e45..7356768 100644
--- a/src/openvic-simulation/types/Date.cpp
+++ b/src/openvic-simulation/types/Date.cpp
@@ -100,6 +100,12 @@ std::ostream& OpenVic::operator<<(std::ostream& out, Timespan const& timespan) {
return out << timespan.to_string();
}
+const std::string Date::MONTH_NAMES[MONTHS_IN_YEAR] = {
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November",
+ "December"
+};
+
Timespan Date::_date_to_timespan(year_t year, month_t month, day_t day) {
month = std::clamp<month_t>(month, 1, MONTHS_IN_YEAR);
day = std::clamp<day_t>(day, 1, DAYS_IN_MONTH[month - 1]);
@@ -208,6 +214,15 @@ bool Date::in_range(Date start, Date end) const {
return start <= *this && *this <= end;
}
+std::string const& Date::get_month_name() const {
+ const month_t month = get_month();
+ if (1 <= month && month <= MONTHS_IN_YEAR) {
+ return MONTH_NAMES[month - 1];
+ }
+ static const std::string invalid_month_name = "Invalid Month";
+ return invalid_month_name;
+}
+
std::string Date::to_string() const {
std::stringstream ss;
ss << *this;