diff options
author | Hop311 <Hop3114@gmail.com> | 2023-05-22 17:54:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 17:54:15 +0200 |
commit | 08ec6fe5fbf52d814d88c235aac84bb95ad4e322 (patch) | |
tree | 136a221eb5e7c895c8219778b3d206f2ed9e8e7f /src/openvic/Date.cpp | |
parent | 15e960f93ced8c94a6a45ebb2b44d0705ff7f8f6 (diff) | |
parent | 7874702f30d5855319faf197b10aed31f07f5e27 (diff) |
Merge pull request #5 from OpenVicProject/bmp
BMP palette parser + code style cleanup
Diffstat (limited to 'src/openvic/Date.cpp')
-rw-r--r-- | src/openvic/Date.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/openvic/Date.cpp b/src/openvic/Date.cpp index d25e99f..f7bf9a3 100644 --- a/src/openvic/Date.cpp +++ b/src/openvic/Date.cpp @@ -1,13 +1,13 @@ #include "Date.hpp" -#include <cctype> #include <algorithm> +#include <cctype> -#include "Logger.hpp" +#include "utility/Logger.hpp" using namespace OpenVic; -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& OpenVic::operator<<(std::ostream& out, Date const& 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 @@ -140,17 +139,17 @@ Date Date::from_string(std::string const& date) { size_t first_pos = 0; while (first_pos < date.length() && std::isdigit(date[first_pos++])); - year = atoi(date.substr(0, first_pos).c_str()); + year = stoi(date.substr(0, first_pos)); 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++])); - month = atoi(date.substr(first_pos, second_pos - first_pos).c_str()); + month = stoi(date.substr(first_pos, second_pos - first_pos)); 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++])); - day = atoi(date.substr(second_pos, third_pos - second_pos).c_str()); + day = stoi(date.substr(second_pos, third_pos - second_pos)); if (third_pos < date.length()) Logger::error("Unexpected string \"", date.substr(third_pos), "\" at the end of date ", date); } else Logger::error("Unexpected character \"", date[second_pos], "\" in date ", date); |