1 // 2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net> 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // === 17 /// 18 /// \file gtime.h 19 /// 20 21 #ifndef G_TIME_H 22 #define G_TIME_H 23 24 #include "gdef.h" 25 #include "gexception.h" 26 #include "gdatetime.h" 27 #include <ctime> 28 29 /// \namespace G 30 namespace G 31 { 32 class Time ; 33 } 34 35 /// \class G::Time 36 /// A simple time-of-day (hh/mm/ss) class. 37 /// \see G::Date, G::DateTime 38 /// 39 class G::Time 40 { 41 public: 42 /// An overload discriminator class for Time constructors. 43 class LocalTime 44 {} ; 45 46 Time() ; 47 ///< Constructor, using UTC, for now. 48 49 explicit Time( const G::DateTime::BrokenDownTime & tm ) ; 50 ///< Constructor for the given broken-down time. 51 52 explicit Time( G::DateTime::EpochTime t ) ; 53 ///< Constructor, using UTC, for the given epoch time. 54 55 Time( G::DateTime::EpochTime t , const LocalTime & ) ; 56 ///< Constructor, using the local timezone, for the given epoch time. 57 58 explicit Time( const LocalTime & ) ; 59 ///< Localtime constructor for now. 60 61 int hours() const ; 62 ///< Returns the hours (0 <= h < 24). 63 64 int minutes() const ; 65 ///< Returns the minutes (0 <= m < 60). 66 67 int seconds() const ; 68 ///< Returns the seconds (0 <= s <= 61 [sic]). 69 70 std::string hhmmss( const char * sep = NULL ) const ; 71 ///< Returns a hhmmss string. 72 73 std::string hhmm( const char * sep = NULL ) const ; 74 ///< Returns a hhmm string. 75 76 std::string ss() const ; 77 ///< Returns the seconds as a two-digit decimal seconds. 78 79 private: 80 int m_hh ; 81 int m_mm ; 82 int m_ss ; 83 } ; 84 85 #endif 86