diff options
Diffstat (limited to 'extension/src/openvic2/Date.hpp')
-rw-r--r-- | extension/src/openvic2/Date.hpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/extension/src/openvic2/Date.hpp b/extension/src/openvic2/Date.hpp index b19602b..b7b45a3 100644 --- a/extension/src/openvic2/Date.hpp +++ b/extension/src/openvic2/Date.hpp @@ -1,15 +1,17 @@ #pragma once #include <cstdint> -#include <string> #include <ostream> +#include <string> namespace OpenVic2 { // A relative period between points in time, measured in days struct Timespan { using day_t = int64_t; + private: day_t days; + public: Timespan(day_t value = 0); @@ -33,7 +35,7 @@ namespace OpenVic2 { explicit operator double() const; explicit operator std::string() const; }; - std::ostream& operator<< (std::ostream& out, Timespan timespan); + std::ostream& operator<<(std::ostream& out, Timespan timespan); // Represents an in-game date // Note: Current implementation does not account for leap-years, or dates before Year 0 @@ -46,11 +48,13 @@ namespace OpenVic2 { static constexpr Timespan::day_t DAYS_IN_YEAR = 365; static constexpr Timespan::day_t DAYS_IN_MONTH[MONTHS_IN_YEAR] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static constexpr Timespan::day_t DAYS_UP_TO_MONTH[MONTHS_IN_YEAR] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; + private: // Number of days since Jan 1st, Year 0 Timespan timespan; static Timespan _dateToTimespan(year_t year, month_t month, day_t day); + public: // The Timespan is considered to be the number of days since Jan 1st, Year 0 Date(Timespan total_days); @@ -79,5 +83,5 @@ namespace OpenVic2 { // Parsed from string of the form YYYY.MM.DD static Date from_string(std::string const& date); }; - std::ostream& operator<< (std::ostream& out, Date date); + std::ostream& operator<<(std::ostream& out, Date date); } |