diff options
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r-- | src/openvic-simulation/types/Date.cpp | 22 | ||||
-rw-r--r-- | src/openvic-simulation/types/Date.hpp | 14 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/openvic-simulation/types/Date.cpp b/src/openvic-simulation/types/Date.cpp index e695e45..1b15e45 100644 --- a/src/openvic-simulation/types/Date.cpp +++ b/src/openvic-simulation/types/Date.cpp @@ -84,15 +84,15 @@ Timespan::operator std::string() const { return to_string(); } -Timespan Timespan::fromYears(day_t num) { +Timespan Timespan::from_years(day_t num) { return num * Date::DAYS_IN_YEAR; } -Timespan Timespan::fromMonths(day_t num) { +Timespan Timespan::from_months(day_t num) { return (num / Date::MONTHS_IN_YEAR) * Date::DAYS_IN_YEAR + Date::DAYS_UP_TO_MONTH[num % Date::MONTHS_IN_YEAR]; } -Timespan Timespan::fromDays(day_t num) { +Timespan Timespan::from_days(day_t num) { return num; } @@ -100,7 +100,7 @@ std::ostream& OpenVic::operator<<(std::ostream& out, Timespan const& timespan) { return out << timespan.to_string(); } -Timespan Date::_dateToTimespan(year_t year, month_t month, day_t day) { +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]); return year * DAYS_IN_YEAR + DAYS_UP_TO_MONTH[month - 1] + day - 1; @@ -142,18 +142,18 @@ Date::Date(Timespan total_days) : timespan { total_days } { } } -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 { _date_to_timespan(year, month, day) } {} -Date::year_t Date::getYear() const { +Date::year_t Date::get_year() const { return static_cast<Timespan::day_t>(timespan) / DAYS_IN_YEAR; } -Date::month_t Date::getMonth() const { +Date::month_t Date::get_month() const { return MONTH_FROM_DAY_IN_YEAR[static_cast<Timespan::day_t>(timespan) % DAYS_IN_YEAR]; } -Date::day_t Date::getDay() const { - return (static_cast<Timespan::day_t>(timespan) % DAYS_IN_YEAR) - DAYS_UP_TO_MONTH[getMonth() - 1] + 1; +Date::day_t Date::get_day() const { + return (static_cast<Timespan::day_t>(timespan) % DAYS_IN_YEAR) - DAYS_UP_TO_MONTH[get_month() - 1] + 1; } bool Date::operator<(Date other) const { @@ -219,8 +219,8 @@ Date::operator std::string() const { } std::ostream& OpenVic::operator<<(std::ostream& out, Date date) { - return out << static_cast<int>(date.getYear()) << Date::SEPARATOR_CHARACTER << static_cast<int>(date.getMonth()) - << Date::SEPARATOR_CHARACTER << static_cast<int>(date.getDay()); + return out << static_cast<int>(date.get_year()) << Date::SEPARATOR_CHARACTER << static_cast<int>(date.get_month()) + << Date::SEPARATOR_CHARACTER << static_cast<int>(date.get_day()); } // Parsed from string of the form YYYY.MM.DD diff --git a/src/openvic-simulation/types/Date.hpp b/src/openvic-simulation/types/Date.hpp index 5aed49b..cce1308 100644 --- a/src/openvic-simulation/types/Date.hpp +++ b/src/openvic-simulation/types/Date.hpp @@ -38,9 +38,9 @@ namespace OpenVic { std::string to_string() const; explicit operator std::string() const; - static Timespan fromYears(day_t num); - static Timespan fromMonths(day_t num); - static Timespan fromDays(day_t num); + static Timespan from_years(day_t num); + static Timespan from_months(day_t num); + static Timespan from_days(day_t num); }; std::ostream& operator<<(std::ostream& out, Timespan const& timespan); @@ -63,7 +63,7 @@ namespace OpenVic { // Number of days since Jan 1st, Year 0 Timespan timespan; - static Timespan _dateToTimespan(year_t year, month_t month, day_t day); + static Timespan _date_to_timespan(year_t year, month_t month, day_t day); static Timespan::day_t const* generate_days_up_to_month(); static month_t const* generate_month_from_day_in_year(); @@ -73,9 +73,9 @@ namespace OpenVic { // Year month day specification Date(year_t year = 0, month_t month = 1, day_t day = 1); - year_t getYear() const; - month_t getMonth() const; - day_t getDay() const; + year_t get_year() const; + month_t get_month() const; + day_t get_day() const; bool operator<(Date other) const; bool operator>(Date other) const; |