aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types/Date.cpp
diff options
context:
space:
mode:
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;