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 
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
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
static Offset offset(EpochTime epoch_time)
Returns the offset between UTC and localtime as at 'epoch_time'.
Definition: gdatetime.cpp:71
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
Definition: gdatetime.cpp:63
Low-level classes.
std::pair< bool, unsigned int > Offset
Definition: gdatetime.h:44
A low-level static class used by Date and Time.
Definition: gdatetime.h:38
static std::string offsetString(Offset offset)
Converts the given utc/localtime offset into a five-character "+/-hhmm" string.
Definition: gdatetime.cpp:81
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
struct std::tm BrokenDownTime
Definition: gdatetime.h:43
static EpochTime epochTime(const BrokenDownTime &broken_down_time)
Converts from UTC broken-down-time to epoch time.
Definition: gdatetime.cpp:39