libcommonc++  0.7
DateTime.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_DateTime_hxx
24 #define __ccxx_DateTime_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/Date.h++>
28 #include <commonc++/String.h++>
29 #include <commonc++/Time.h++>
30 #include <commonc++/TimeSpan.h++>
31 
32 namespace ccxx {
33 
38 class COMMONCPP_API DateTime : public Date, public Time
39 {
40  public:
41 
43  DateTime(time_s_t time);
44 
46  DateTime(time_ms_t time = 0);
47 
49  DateTime(uint_t day, uint_t month, uint_t year, uint_t hour = 0,
50  uint_t minute = 0, uint_t second = 0, uint_t msec = 0);
51 
53  DateTime(const Date& date, const Time& time);
54 
56  DateTime(const Date& date);
57 
59  DateTime(const Time& time);
60 
62  DateTime(const DateTime& other);
63 
65  virtual ~DateTime();
66 
72  DateTime& normalize();
73 
75  operator time_s_t() const;
76 
78  operator time_ms_t() const;
79 
80  bool operator==(const DateTime& other) const;
81  bool operator<(const DateTime& other) const;
82  bool operator<=(const DateTime& other) const;
83 
84  inline bool operator!=(const DateTime& other) const
85  { return(! operator==(other)); }
86 
87  inline bool operator>(const DateTime& other) const
88  { return(! operator<=(other)); }
89 
90  inline bool operator>=(const DateTime& other) const
91  { return(! operator<(other)); }
92 
93  DateTime& operator=(time_s_t other);
94  DateTime& operator=(time_ms_t other);
95  DateTime& operator=(const DateTime& other);
96 
98  inline void setTime(uint_t hour, uint_t minute, uint_t second = 0,
99  uint_t msec = 0)
100  { Time::setTime(hour, minute, second, msec); }
101 
103  inline void setDate(uint_t day, uint_t month, uint_t year)
104  { Date::setDate(day, month, year); }
105 
107  DateTime& setDate(const Date& other);
108 
110  DateTime& setTime(const Time& other);
111 
113  DateTime& operator+=(const TimeSpan& span);
114 
116  DateTime& operator-=(const TimeSpan& span);
117 
119  static bool isDSTActive();
120 
122  static int getGMTOffset();
123 
125  static String getTimeZone();
126 };
127 
128 inline const TimeSpan operator-(const DateTime& d1, const DateTime& d2)
129 {
130  time_ms_t t1 = d1;
131  time_ms_t t2 = d2;
132  return TimeSpan(t1 >= t2 ? t1 - t2 : t2 - t1);
133 }
134 
135 inline const DateTime operator-(const DateTime& d, const TimeSpan& ts)
136 {
137  DateTime tmp(d);
138  tmp -= ts;
139  return tmp;
140 }
141 
142 inline const DateTime operator+(const DateTime& d, const TimeSpan& ts)
143 {
144  DateTime tmp(d);
145  tmp += ts;
146  return tmp;
147 }
148 
149 } // namespace ccxx
150 
151 #endif // __ccxx_DateTime_hxx
const TimeSpan operator-(const TimeSpan &s1, const TimeSpan &s2)
Definition: TimeSpan.c++:386
A span of time (a delta), represented in milliseconds.
Definition: TimeSpan.h++:36
A representation of a calendar date.
Definition: Date.h++:35
void setDate(uint_t day, uint_t month, uint_t year)
Set the day, month, and year components of the date.
Definition: Date.c++:132
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
const TimeSpan operator+(const TimeSpan &s1, const TimeSpan &s2)
Definition: TimeSpan.c++:362
bool operator<=(const Blob &b1, const Blob &b2)
Definition: Blob.h++:356
bool operator==(const Blob &b1, const Blob &b2)
Definition: Blob.h++:344
int32_t time_s_t
A time expressed in seconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:85
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
void setDate(uint_t day, uint_t month, uint_t year)
Set the day, month, and year components of the date.
Definition: DateTime.h++:103
bool operator>(const DateTime &other) const
Definition: DateTime.h++:87
bool operator>=(const DateTime &other) const
Definition: DateTime.h++:90
A representation of a clock time.
Definition: Time.h++:37
bool operator!=(const DateTime &other) const
Definition: DateTime.h++:84
#define COMMONCPP_API
Definition: Common.h++:126
void setTime(uint_t hour, uint_t minute, uint_t second=0, uint_t msec=0)
Set the hour, minute, second, and millisecond components of the time.
Definition: Time.c++:122
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
bool operator<(const Blob &b1, const Blob &b2)
Definition: Blob.h++:350
void setTime(uint_t hour, uint_t minute, uint_t second=0, uint_t msec=0)
Set the hour, minute, second, and millisecond components of the time.
Definition: DateTime.h++:98
A representation of a calendar date and clock time.
Definition: DateTime.h++:38
Definition: AllocationMap.c++:25