...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::date_time::base_time — Representation of a precise moment in time, including the date.
// In header: <boost/date_time/time.hpp> template<typename T, typename time_system> class base_time : private boost::less_than_comparable< T, boost::equality_comparable< T > > { public: // types typedef void _is_boost_date_time_time_point; typedef T time_type; typedef time_system::time_rep_type time_rep_type; typedef time_system::date_type date_type; typedef time_system::date_duration_type date_duration_type; typedef time_system::time_duration_type time_duration_type; // construct/copy/destruct base_time(const date_type &, const time_duration_type &, dst_flags = not_dst); base_time(special_values); base_time(const time_rep_type &); // public member functions BOOST_CXX14_CONSTEXPR date_type date() const; BOOST_CXX14_CONSTEXPR time_duration_type time_of_day() const; std::string zone_name(bool = false) const; std::string zone_abbrev(bool = false) const; std::string zone_as_posix_string() const; BOOST_CXX14_CONSTEXPR bool is_not_a_date_time() const; BOOST_CXX14_CONSTEXPR bool is_infinity() const; BOOST_CXX14_CONSTEXPR bool is_pos_infinity() const; BOOST_CXX14_CONSTEXPR bool is_neg_infinity() const; BOOST_CXX14_CONSTEXPR bool is_special() const; BOOST_CXX14_CONSTEXPR bool operator==(const time_type &) const; BOOST_CXX14_CONSTEXPR bool operator<(const time_type &) const; BOOST_CXX14_CONSTEXPR time_duration_type operator-(const time_type &) const; BOOST_CXX14_CONSTEXPR time_type operator+(const date_duration_type &) const; BOOST_CXX14_CONSTEXPR time_type operator+=(const date_duration_type &); BOOST_CXX14_CONSTEXPR time_type operator-(const date_duration_type &) const; BOOST_CXX14_CONSTEXPR time_type operator-=(const date_duration_type &); BOOST_CXX14_CONSTEXPR time_type operator+(const time_duration_type &) const; BOOST_CXX14_CONSTEXPR time_type operator+=(const time_duration_type &); BOOST_CXX14_CONSTEXPR time_type operator-(const time_duration_type &) const; BOOST_CXX14_CONSTEXPR time_type operator-=(const time_duration_type &); };
This class is a skeleton for the interface of a temporal type with a resolution that is higher than a day. It is intended that this class be the base class and that the actual time class be derived using the BN pattern. In this way, the derived class can make decisions such as 'should there be a default constructor' and what should it set its value to, should there be optional constructors say allowing only an time_durations that generate a time from a clock,etc. So, in fact multiple time types can be created for a time_system with different construction policies, and all of them can perform basic operations by only writing a copy constructor. Finally, compiler errors are also shorter.
The real behavior of the time class is provided by the time_system template parameter. This class must provide all the logic for addition, subtraction, as well as define all the interface types.
base_time
public member functionsBOOST_CXX14_CONSTEXPR date_type date() const;
BOOST_CXX14_CONSTEXPR time_duration_type time_of_day() const;
std::string zone_name(bool = false) const;
Optional bool parameter will return time zone as an offset (ie "+07:00"). Empty string is returned for classes that do not use a time_zone
std::string zone_abbrev(bool = false) const;
Optional bool parameter will return time zone as an offset (ie "+07:00"). Empty string is returned for classes that do not use a time_zone
std::string zone_as_posix_string() const;An empty string is returned for classes that do not use a time_zone.
BOOST_CXX14_CONSTEXPR bool is_not_a_date_time() const;check to see if date is not a value
BOOST_CXX14_CONSTEXPR bool is_infinity() const;check to see if date is one of the infinity values
BOOST_CXX14_CONSTEXPR bool is_pos_infinity() const;check to see if date is greater than all possible dates
BOOST_CXX14_CONSTEXPR bool is_neg_infinity() const;check to see if date is greater than all possible dates
BOOST_CXX14_CONSTEXPR bool is_special() const;check to see if time is a special value
BOOST_CXX14_CONSTEXPR bool operator==(const time_type & rhs) const;Equality operator – others generated by boost::equality_comparable.
BOOST_CXX14_CONSTEXPR bool operator<(const time_type & rhs) const;Equality operator – others generated by boost::less_than_comparable.
BOOST_CXX14_CONSTEXPR time_duration_type operator-(const time_type & rhs) const;difference between two times
BOOST_CXX14_CONSTEXPR time_type operator+(const date_duration_type & dd) const;add date durations
BOOST_CXX14_CONSTEXPR time_type operator+=(const date_duration_type & dd);
BOOST_CXX14_CONSTEXPR time_type operator-(const date_duration_type & dd) const;subtract date durations
BOOST_CXX14_CONSTEXPR time_type operator-=(const date_duration_type & dd);
BOOST_CXX14_CONSTEXPR time_type operator+(const time_duration_type & td) const;add time durations
BOOST_CXX14_CONSTEXPR time_type operator+=(const time_duration_type & td);
BOOST_CXX14_CONSTEXPR time_type operator-(const time_duration_type & rhs) const;subtract time durations
BOOST_CXX14_CONSTEXPR time_type operator-=(const time_duration_type & td);