1 #ifndef TOURNAMENT_RUNNER_DATE_H_
2 #define TOURNAMENT_RUNNER_DATE_H_
7 #include <boost/date_time/gregorian/gregorian.hpp>
8 #include <boost/serialization/nvp.hpp>
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/split_member.hpp>
12 using boost::serialization::make_nvp;
14 namespace TournamentRunner
33 explicit Date (
const std::string& date_as_string);
39 explicit Date (boost::gregorian::date date);
57 int32_t
year ()
const;
62 int32_t
month ()
const;
69 Date& operator= (
const Date&) =
default;
73 static boost::gregorian::date date_from_string (
const std::string& date_as_string);
75 friend class boost::serialization::access;
77 friend bool operator==(
const Date&,
const Date&);
82 template<
class Archive>
83 void save (Archive& archive,
84 const unsigned int version)
const;
89 template<
class Archive>
90 void load (Archive& archive,
91 const unsigned int version);
93 BOOST_SERIALIZATION_SPLIT_MEMBER()
95 boost::gregorian::date date_{boost::gregorian::day_clock::local_day()};
98 bool operator== (
const Date& lhs,
const Date& rhs);
100 bool operator!= (
const Date& lhs,
const Date& rhs);
102 std::ostream& operator<<(std::ostream& os,
105 template<
class Archive>
106 void Date::save (Archive& archive,
107 const unsigned int )
const
109 const auto date_as_string = boost::gregorian::to_iso_extended_string(date_);
110 archive & make_nvp(
"Date", date_as_string);
113 template<
class Archive>
114 void Date::load (Archive& archive,
117 auto date_as_string = std::string{};
118 archive & make_nvp(
"Date", date_as_string);
119 date_ = boost::gregorian::from_simple_string(date_as_string);
124 #endif //TOURNAMENT_RUNNER_DATE_H_
int32_t day() const
Return the day of month.
Definition: date.cpp:38
Date()=default
Default empty Date constructor.
std::string to_iso_extended_string() const
Return date as extended iso string.
Definition: date.cpp:23
int32_t month() const
Return the month.
Definition: date.cpp:33
bool is_valid() const
Return true if the date is valid.
Definition: date.cpp:18
The Date class provides Date handling based on the boost::gregorian::date.
Definition: date.h:21
int32_t year() const
Return the year.
Definition: date.cpp:28