// Time.h #ifndef dset__Time_H #define dset__Time_H // Class to hold time and time interval. #include #include class TimeInterval; // Absolute time. class Time { public: // static methods // Reuturn the current time. static Time now(); private: // data unsigned long m_time; public: // methods // Constructor. // Default is invalid. explicit Time(unsigned long tim =0); // Set the time to now. Time& set(); // Add a time interval. Time& operator+=(TimeInterval dtim); // Subtract a time interval. Time& operator-=(TimeInterval dtim); // Is this a valid time (nonzero). bool is_valid() const; // Unix time (seconds since 1970). unsigned long unix_time() const; // Formatted UTC. // e.g. 2005 Jun 21 16:45:33 std::string to_string() const; }; // Time interval. class TimeInterval { private: // data long m_dtime; public: // methods // Constructor from interval in seconds. explicit TimeInterval(long dtime =0); // Constructor from start and stop times. TimeInterval(Time start, Time stop); // Add a time interval. TimeInterval& operator+=(TimeInterval dtim); // Subtract a time interval. TimeInterval& operator-=(TimeInterval dtim); // Time interval in seconds. long seconds() const; // Formatted dys:hrs:min:sec. // E.g. 3:05:35:22 std::string to_string() const; }; // Time output stream. std::ostream& operator<<(std::ostream& lhs, const Time& rhs); // TimeInterval output stream. std::ostream& operator<<(std::ostream& lhs, const TimeInterval& rhs); #endif