- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gdatetime.h
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 // ===
20
21 #ifndef G_DATE_TIME_H
22 #define G_DATE_TIME_H
23
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <ctime>
27 #include <string>
28
30 namespace G
31 {
32 class DateTime ;
33 }
34
38 class G::DateTime
39 {
40 public:
41 G_EXCEPTION( Error , "date/time error" ) ;
42 typedef std::time_t EpochTime ;
43 typedef struct std::tm BrokenDownTime ;
44 typedef std::pair<bool,unsigned int> Offset ;
45
46 static EpochTime now() ;
48
49 static EpochTime epochTime( const BrokenDownTime & broken_down_time ) ;
51
52 static BrokenDownTime utc( EpochTime epoch_time ) ;
54
55 static BrokenDownTime local( EpochTime epoch_time ) ;
57
58 static Offset offset( EpochTime epoch_time ) ;
65
66 static std::string offsetString( Offset offset ) ;
70
71 private:
72 static bool equivalent( EpochTime , const BrokenDownTime & ) ;
73 static bool same( const BrokenDownTime & , const BrokenDownTime & ) ;
74 static std::tm * gmtime_r( const std::time_t * , std::tm * ) ;
75 static std::tm * localtime_r( const std::time_t * , std::tm * ) ;
76 DateTime() ; // not implemented
77 } ;
78
79 #endif
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::DateTime::offset
static Offset offset(EpochTime epoch_time)
Returns the offset between UTC and localtime as at 'epoch_time'.
Definition: gdatetime.cpp:71
G::DateTime::local
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
Definition: gdatetime.cpp:63
G
Low-level classes.
G::DateTime::Offset
std::pair< bool, unsigned int > Offset
Definition: gdatetime.h:44
G::DateTime
A low-level static class used by Date and Time.
Definition: gdatetime.h:38
G::DateTime::offsetString
static std::string offsetString(Offset offset)
Converts the given utc/localtime offset into a five-character "+/-hhmm" string.
Definition: gdatetime.cpp:81
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
G::DateTime::BrokenDownTime
struct std::tm BrokenDownTime
Definition: gdatetime.h:43
G::DateTime::epochTime
static EpochTime epochTime(const BrokenDownTime &broken_down_time)
Converts from UTC broken-down-time to epoch time.
Definition: gdatetime.cpp:39