gtime.cpp
Go to the documentation of this file.
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 // gtime.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gtime.h"
23 #include "gdatetime.h"
24 #include "gassert.h"
25 
27 {
28  m_hh = tm.tm_hour ;
29  m_mm = tm.tm_min ;
30  m_ss = tm.tm_sec ;
31 }
32 
34 {
36  m_hh = tm.tm_hour ;
37  m_mm = tm.tm_min ;
38  m_ss = tm.tm_sec ;
39 }
40 
42 {
44  m_hh = tm.tm_hour ;
45  m_mm = tm.tm_min ;
46  m_ss = tm.tm_sec ;
47 }
48 
50 {
52  m_hh = tm.tm_hour ;
53  m_mm = tm.tm_min ;
54  m_ss = tm.tm_sec ;
55 }
56 
58 {
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 == NULL ) 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 == NULL ) 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 
static BrokenDownTime utc(EpochTime epoch_time)
Converts from epoch time to UTC broken-down-time.
Definition: gdatetime.cpp:55
static EpochTime now()
Returns the current epoch time.
Definition: gdatetime.cpp:34
std::time_t EpochTime
Definition: gdatetime.h:41
std::string hhmm(const char *sep=NULL) const
Returns a hhmm string.
Definition: gtime.cpp:88
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
Definition: gdatetime.cpp:63
std::string ss() const
Returns the seconds as a two-digit decimal seconds.
Definition: gtime.cpp:96
Time()
Constructor, using UTC, for now.
Definition: gtime.cpp:33
An overload discriminator class for Time constructors.
Definition: gtime.h:43
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
struct std::tm BrokenDownTime
Definition: gdatetime.h:43
std::string hhmmss(const char *sep=NULL) const
Returns a hhmmss string.
Definition: gtime.cpp:80
int seconds() const
Returns the seconds (0 <= s <= 61 [sic]).
Definition: gtime.cpp:75