VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gtime.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
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 {
31  class Time ;
32 }
33 
34 /// \class G::Time
35 /// A simple time-of-day (hh/mm/ss) class.
36 /// \see G::Date, G::DateTime
37 ///
38 class G::Time
39 {
40 public:
41  class LocalTime /// An overload discriminator class for Time constructors.
42  {} ;
43 
44  Time() ;
45  ///< Constructor for the current time, using UTC.
46 
47  explicit Time( const G::DateTime::BrokenDownTime & tm ) ;
48  ///< Constructor for the given broken-down time.
49 
50  explicit Time( G::EpochTime t ) ;
51  ///< Constructor for the given epoch time, using UTC.
52 
53  Time( G::EpochTime t , const LocalTime & ) ;
54  ///< Constructor for the given epoch time, using the local timezone.
55 
56  explicit Time( const LocalTime & ) ;
57  ///< Constructor for the current time, using the local timezone.
58 
59  int hours() const ;
60  ///< Returns the hours (0 <= h < 24).
61 
62  int minutes() const ;
63  ///< Returns the minutes (0 <= m < 60).
64 
65  int seconds() const ;
66  ///< Returns the seconds (0 <= s <= 61).
67 
68  std::string hhmmss( const char * sep = nullptr ) const ;
69  ///< Returns the hhmmss string.
70 
71  std::string hhmm( const char * sep = nullptr ) const ;
72  ///< Returns the hhmm string.
73 
74  std::string ss() const ;
75  ///< Returns the seconds as a two-digit decimal string.
76 
77 private:
78  int m_hh ;
79  int m_mm ;
80  int m_ss ;
81 } ;
82 
83 #endif
std::string hhmmss(const char *sep=nullptr) const
Returns the hhmmss string.
Definition: gtime.cpp:80
A subsecond-resolution timestamp based on a time_t.
Definition: gdatetime.h:39
std::string ss() const
Returns the seconds as a two-digit decimal string.
Definition: gtime.cpp:96
A simple time-of-day (hh/mm/ss) class.
Definition: gtime.h:38
Time()
Constructor for the current time, using UTC.
Definition: gtime.cpp:33
An overload discriminator class for Time constructors.
Definition: gtime.h:41
int minutes() const
Returns the minutes (0 <= m < 60).
Definition: gtime.cpp:70
int hours() const
Returns the hours (0 <= h < 24).
Definition: gtime.cpp:65
std::string hhmm(const char *sep=nullptr) const
Returns the hhmm string.
Definition: gtime.cpp:88
int seconds() const
Returns the seconds (0 <= s <= 61).
Definition: gtime.cpp:75