- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
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
33 G::Time::Time()
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
41 G::Time::Time( G::DateTime::EpochTime t )
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
49 G::Time::Time( const LocalTime & )
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
57 G::Time::Time( G::DateTime::EpochTime t , const LocalTime & )
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 == 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
G::DateTime::utc
static BrokenDownTime utc(EpochTime epoch_time)
Converts from epoch time to UTC broken-down-time.
Definition: gdatetime.cpp:55
G::DateTime::now
static EpochTime now()
Returns the current epoch time.
Definition: gdatetime.cpp:34
G::DateTime::EpochTime
std::time_t EpochTime
Definition: gdatetime.h:41
G::Time::hhmm
std::string hhmm(const char *sep=NULL) const
Returns a hhmm string.
Definition: gtime.cpp:88
G::DateTime::local
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
Definition: gdatetime.cpp:63
G::Time::ss
std::string ss() const
Returns the seconds as a two-digit decimal seconds.
Definition: gtime.cpp:96
gtime.h
G::Time::Time
Time()
Constructor, using UTC, for now.
Definition: gtime.cpp:33
gassert.h
G::Time::LocalTime
An overload discriminator class for Time constructors.
Definition: gtime.h:43
gdatetime.h
G::Time::minutes
int minutes() const
Returns the minutes (0 <= m < 60).
Definition: gtime.cpp:70
G::Time::hours
int hours() const
Returns the hours (0 <= h < 24).
Definition: gtime.cpp:65
G::DateTime::BrokenDownTime
struct std::tm BrokenDownTime
Definition: gdatetime.h:43
G::Time::hhmmss
std::string hhmmss(const char *sep=NULL) const
Returns a hhmmss string.
Definition: gtime.cpp:80
G::Time::seconds
int seconds() const
Returns the seconds (0 <= s <= 61 [sic]).
Definition: gtime.cpp:75