aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/Date.cpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-04-24 05:36:42 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-05-02 00:50:24 +0200
commit112de0ac9c7ce26bd75d06e4cd3bc91adee716e3 (patch)
tree8c2376ce06c164e10fe815723e5601f2a7bebf02 /extension/src/openvic2/Date.cpp
parentb1e985e0774598b3add22069be50f891e981fd79 (diff)
Support features up to clang-format 14
Add .editorconfig Update C++ files within `extension/src` to follow .clang-format
Diffstat (limited to 'extension/src/openvic2/Date.cpp')
-rw-r--r--extension/src/openvic2/Date.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/extension/src/openvic2/Date.cpp b/extension/src/openvic2/Date.cpp
index ed800d5..11e4b36 100644
--- a/extension/src/openvic2/Date.cpp
+++ b/extension/src/openvic2/Date.cpp
@@ -1,13 +1,13 @@
#include "Date.hpp"
-#include <cctype>
#include <algorithm>
+#include <cctype>
#include "Logger.hpp"
using namespace OpenVic2;
-Timespan::Timespan(day_t value) : days{value} {}
+Timespan::Timespan(day_t value) : days { value } {}
bool Timespan::operator<(Timespan other) const { return days < other.days; };
bool Timespan::operator>(Timespan other) const { return days > other.days; };
@@ -67,14 +67,14 @@ Timespan Date::_dateToTimespan(year_t year, month_t month, day_t day) {
return year * DAYS_IN_YEAR + DAYS_UP_TO_MONTH[month - 1] + day - 1;
}
-Date::Date(Timespan total_days) : timespan{ total_days } {
+Date::Date(Timespan total_days) : timespan { total_days } {
if (timespan < 0) {
Logger::error("Invalid timespan for date: ", timespan, " (cannot be negative)");
timespan = 0;
}
}
-Date::Date(year_t year, month_t month, day_t day) : timespan{ _dateToTimespan(year, month, day) } {}
+Date::Date(year_t year, month_t month, day_t day) : timespan { _dateToTimespan(year, month, day) } {}
Date::year_t Date::getYear() const {
return static_cast<Timespan::day_t>(timespan) / DAYS_IN_YEAR;
@@ -89,7 +89,6 @@ Date::day_t Date::getDay() const {
return days_in_year - DAYS_UP_TO_MONTH[days_in_year / 32] + 1;
}
-
bool Date::operator<(Date other) const { return timespan < other.timespan; };
bool Date::operator>(Date other) const { return timespan > other.timespan; };
bool Date::operator<=(Date other) const { return timespan <= other.timespan; };
@@ -129,7 +128,7 @@ Date::operator std::string() const {
}
std::ostream& OpenVic2::operator<<(std::ostream& out, Date date) {
- return out << (int) date.getYear() << '.' << (int) date.getMonth() << '.' << (int) date.getDay();
+ return out << (int)date.getYear() << '.' << (int)date.getMonth() << '.' << (int)date.getDay();
}
// Parsed from string of the form YYYY.MM.DD
@@ -139,17 +138,20 @@ Date Date::from_string(std::string const& date) {
day_t day = 1;
size_t first_pos = 0;
- while (first_pos < date.length() && std::isdigit(date[first_pos++]));
+ while (first_pos < date.length() && std::isdigit(date[first_pos++]))
+ ;
year = atoi(date.substr(0, first_pos).c_str());
if (first_pos < date.length()) {
if (date[first_pos] == '.') {
size_t second_pos = first_pos + 1;
- while (second_pos < date.length() && std::isdigit(date[second_pos++]));
+ while (second_pos < date.length() && std::isdigit(date[second_pos++]))
+ ;
month = atoi(date.substr(first_pos, second_pos - first_pos).c_str());
if (second_pos < date.length()) {
if (date[second_pos] == '.') {
size_t third_pos = second_pos + 1;
- while (third_pos < date.length() && std::isdigit(date[third_pos++]));
+ while (third_pos < date.length() && std::isdigit(date[third_pos++]))
+ ;
day = atoi(date.substr(second_pos, third_pos - second_pos).c_str());
if (third_pos < date.length())
Logger::error("Unexpected string \"", date.substr(third_pos), "\" at the end of date ", date);