E-MailRelay
gtime.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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
29namespace 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///
39{
40public:
41 class LocalTime /// An overload discriminator class for Time constructors.
42 {} ;
43
44 Time() ;
45 ///< Constructor for the current time, using UTC.
46
47 Time( int hh , int mm , int ss ) ;
48 ///< Constructor for the given time. Out-of-range values are
49 ///< clamped, with leap seconds allowed only just before
50 ///< midnight.
51
52 explicit Time( const BrokenDownTime & tm ) ;
53 ///< Constructor for the given broken-down time.
54
55 explicit Time( SystemTime t ) ;
56 ///< Constructor for the given epoch time, using UTC.
57
58 Time( SystemTime t , const LocalTime & ) ;
59 ///< Constructor for the given epoch time, using the local timezone.
60
61 explicit Time( const LocalTime & ) ;
62 ///< Constructor for the current time, using the local timezone.
63
64 static Time at( unsigned int ) ;
65 ///< Factory function for a time that is the given number of
66 ///< seconds since midnight (see value()). Values that are out
67 ///< of the normal time-of-day range are clamped, with leap
68 ///< seconds beging lost in the process.
69
70 int hours() const ;
71 ///< Returns the hours (0 <= h < 24).
72
73 int minutes() const ;
74 ///< Returns the minutes (0 <= m < 60).
75
76 int seconds() const ;
77 ///< Returns the seconds (0 <= s <= 61).
78
79 std::string hhmmss( const char * sep = nullptr ) const ;
80 ///< Returns the hhmmss string.
81
82 std::string hhmm( const char * sep = nullptr ) const ;
83 ///< Returns the hhmm string.
84
85 std::string ss() const ;
86 ///< Returns the seconds as a two-digit decimal string.
87
88 unsigned int value() const ;
89 ///< Returns the time as the number of seconds since midnight
90 ///< (ignoring leap seconds).
91
92 bool operator==( const Time & ) const ;
93 ///< Comparison operator.
94
95 bool operator!=( const Time & ) const ;
96 ///< Comparison operator.
97
98private:
99 int m_hh ;
100 int m_mm ;
101 int m_ss ;
102} ;
103
104#endif
An encapsulation of 'struct std::tm'.
Definition: gdatetime.h:45
Represents a unix-epoch time with microsecond resolution.
Definition: gdatetime.h:125
An overload discriminator class for Time constructors.
Definition: gtime.h:42
A simple time-of-day (hh/mm/ss) class.
Definition: gtime.h:39
bool operator==(const Time &) const
Comparison operator.
Definition: gtime.cpp:117
unsigned int value() const
Returns the time as the number of seconds since midnight (ignoring leap seconds).
Definition: gtime.cpp:99
int minutes() const
Returns the minutes (0 <= m < 60).
Definition: gtime.cpp:66
static Time at(unsigned int)
Factory function for a time that is the given number of seconds since midnight (see value()).
Definition: gtime.cpp:107
std::string hhmm(const char *sep=nullptr) const
Returns the hhmm string.
Definition: gtime.cpp:84
int hours() const
Returns the hours (0 <= h < 24).
Definition: gtime.cpp:61
Time()
Constructor for the current time, using UTC.
Definition: gtime.cpp:41
std::string ss() const
Returns the seconds as a two-digit decimal string.
Definition: gtime.cpp:92
int seconds() const
Returns the seconds (0 <= s <= 61).
Definition: gtime.cpp:71
bool operator!=(const Time &) const
Comparison operator.
Definition: gtime.cpp:122
std::string hhmmss(const char *sep=nullptr) const
Returns the hhmmss string.
Definition: gtime.cpp:76
Low-level classes.
Definition: galign.h:28