VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gtime.cpp
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 // gtime.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gtime.h"
23 #include "gdatetime.h"
24 #include "gassert.h"
25 
26 G::Time::Time( const G::DateTime::BrokenDownTime & tm )
27 {
28  m_hh = tm.tm_hour ;
29  m_mm = tm.tm_min ;
30  m_ss = tm.tm_sec ;
31 }
32 
34 {
35  G::DateTime::BrokenDownTime tm = G::DateTime::utc( G::DateTime::now() ) ;
36  m_hh = tm.tm_hour ;
37  m_mm = tm.tm_min ;
38  m_ss = tm.tm_sec ;
39 }
40 
42 {
43  G::DateTime::BrokenDownTime tm = G::DateTime::utc( t ) ;
44  m_hh = tm.tm_hour ;
45  m_mm = tm.tm_min ;
46  m_ss = tm.tm_sec ;
47 }
48 
50 {
51  G::DateTime::BrokenDownTime tm = G::DateTime::local( G::DateTime::now() ) ;
52  m_hh = tm.tm_hour ;
53  m_mm = tm.tm_min ;
54  m_ss = tm.tm_sec ;
55 }
56 
58 {
59  G::DateTime::BrokenDownTime tm = G::DateTime::local( t ) ;
60  m_hh = tm.tm_hour ;
61  m_mm = tm.tm_min ;
62  m_ss = tm.tm_sec ;
63 }
64 
65 int G::Time::hours() const
66 {
67  return m_hh ;
68 }
69 
70 int G::Time::minutes() const
71 {
72  return m_mm ;
73 }
74 
75 int G::Time::seconds() const
76 {
77  return m_ss ;
78 }
79 
80 std::string G::Time::hhmmss( const char * sep ) const
81 {
82  if( sep == nullptr ) sep = "" ;
83  std::ostringstream ss ;
84  ss << (m_hh/10) << (m_hh%10) << sep << (m_mm/10) << (m_mm%10) << sep << (m_ss/10) << (m_ss%10) ;
85  return ss.str() ;
86 }
87 
88 std::string G::Time::hhmm( const char * sep ) const
89 {
90  if( sep == nullptr ) sep = "" ;
91  std::ostringstream ss ;
92  ss << (m_hh/10) << (m_hh%10) << sep << (m_mm/10) << (m_mm%10) ;
93  return ss.str() ;
94 }
95 
96 std::string G::Time::ss() const
97 {
98  std::ostringstream ss ;
99  ss << (m_ss/10) << (m_ss%10) ;
100  return ss.str() ;
101 }
102 
103 
104 /// \file gtime.cpp
static BrokenDownTime utc(EpochTime epoch_time)
Converts from epoch time to UTC broken-down-time.
Definition: gdatetime.cpp:123
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
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
Definition: gdatetime.cpp:131
std::string ss() const
Returns the seconds as a two-digit decimal string.
Definition: gtime.cpp:96
static EpochTime now()
Returns the current epoch time.
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