#pragma once #include #include #include class Time_hms; // Insert a time into an output stream. std::ostream &operator<<( std::ostream &out, Time_hms const &time ); class Time_hms { public: // Construct a non-negative time. Time_hms( std::uint32_t hours, unsigned int minutes, unsigned int seconds ); // Return if the time is negative, and // the hour, minute, and second components. bool negative() const; std::uint32_t hours() const; std::uint8_t minutes() const; std::uint8_t seconds() const; // Comparison of times bool operator==( Time_hms const &other ) const; bool operator!=( Time_hms const &other ) const; bool operator< ( Time_hms const &other ) const; bool operator<=( Time_hms const &other ) const; bool operator>=( Time_hms const &other ) const; bool operator> ( Time_hms const &other ) const; // Return this time or its additive inverse. Time_hms operator+() const; Time_hms operator-() const; // Add or subtract another time. Time_hms operator+( Time_hms const &other ) const; Time_hms operator-( Time_hms const &other ) const; // Add or subtract another time from this time. Time_hms &operator+=( Time_hms const &other ); Time_hms &operator-=( Time_hms const &other ); // Add or subtract a second from this time. Time_hms &operator++(); Time_hms operator++( int ); Time_hms &operator--(); Time_hms operator--( int ); // Return a string representation of this time. std::string to_string() const; private: std::uint32_t hours_; std::uint8_t minutes_; std::uint8_t seconds_; bool is_negative_; // Construct a time from the components Time_hms( std::uint32_t hours, std::uint8_t minutes, std::uint8_t seconds, bool is_negative ); };