UCommon
numbers.h
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3 // Copyright (C) 2015 Cherokees of Idaho.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38 
39 #ifndef COMMONCPP_NUMBERS_H_
40 #define COMMONCPP_NUMBERS_H_
41 
42 #ifndef COMMONCPP_CONFIG_H_
43 #include <commoncpp/config.h>
44 #endif
45 
46 #ifndef COMMONCPP_STRING_H_
47 #include <commoncpp/string.h>
48 #endif
49 
52 
53 namespace ost {
54 
55 class __EXPORT Date : public ucommon::Date
56 {
57 protected:
58  inline void toJulian(long year, long month, long day) {
59  ucommon::Date::set(year, month, day);
60  }
61 
62  inline void fromJulian(char *buf) const {
63  put(buf);
64  }
65 
66 public:
67  inline Date(time_t value) : ucommon::Date(value) {}
68 
69  inline Date(struct tm *object) : ucommon::Date(object) {}
70 
71  inline Date(const char *ptr, size_t size = 0) : ucommon::Date(ptr, size) {}
72 
73  inline Date(int y, unsigned m, unsigned d) : ucommon::Date(y, m, d) {}
74 
75  inline Date(const Date& object) : ucommon::Date(object) {}
76 
77  inline Date() : ucommon::Date() {}
78 
79  inline int getYear(void) const {
80  return year();
81  }
82 
83  inline unsigned getMonth(void) const {
84  return month();
85  }
86 
87  inline unsigned getDay(void) const {
88  return day();
89  }
90 
91  inline unsigned getDayOfWeek(void) const {
92  return dow();
93  }
94 
95  inline long getJulian(void) const {
96  return julian;
97  }
98 
99  inline const char *get(char *buffer) const {
100  return put(buffer);
101  }
102 
103  inline time_t getTime(void) const {
104  return timeref();
105  }
106 
107  inline bool isValid(void) const {
108  return is_valid();
109  }
110 };
111 
112 class __EXPORT Time : public ucommon::Time
113 {
114 protected:
115  inline void toSeconds(int h, int m = 0, int s = 0) {
116  set(h, m, s);
117  }
118 
119  inline void fromSeconds(char *buf) const {
120  put(buf);
121  }
122 
123 public:
124  inline Time(time_t value) : ucommon::Time(value) {}
125 
126  inline Time(tm_t *object) : ucommon::Time(object) {}
127 
128  inline Time(const char *ptr, size_t size) : ucommon::Time(ptr, size) {}
129 
130  inline Time(int h, int m, int s) : ucommon::Time(h, m, s) {}
131 
132  inline Time(const Time& object) : ucommon::Time(object) {}
133 
134  inline Time() : ucommon::Time() {}
135 
136  inline int getHour(void) const {
137  return hour();
138  }
139 
140  inline int getMinute(void) const {
141  return minute();
142  }
143 
144  inline int getSecond(void) const {
145  return second();
146  }
147 
148  inline const char *get(char *buffer) const {
149  return put(buffer);
150  }
151 
152  inline bool isValid(void) const {
153  return is_valid();
154  }
155 
156 };
157 
158 class __EXPORT DateTime : public ucommon::DateTime
159 {
160 public:
161  inline DateTime(time_t time) : ucommon::DateTime(time) {}
162 
163  inline DateTime(struct tm *dt) : ucommon::DateTime(dt) {}
164 
165 
166  inline DateTime(int year, unsigned month, unsigned day,
167  int hour = 0, int minute = 0, int second = 0) :
168  ucommon::DateTime(year, month, day, hour, minute, second) {}
169 
170  inline DateTime(const char *ptr, size_t size) :
171  ucommon::DateTime(ptr, size) {}
172 
173  inline DateTime(const DateTime& obj) : ucommon::DateTime(obj) {}
174 
175  inline DateTime() : ucommon::DateTime() {}
176 
177  inline int getYear(void) const {
178  return year();
179  }
180 
181  inline unsigned getMonth(void) const {
182  return month();
183  }
184 
185  inline unsigned getDay(void) const {
186  return day();
187  }
188 
189  inline unsigned getDayOfWeek(void) const {
190  return dow();
191  }
192 
193  inline long getJulian(void) const {
194  return julian;
195  }
196 
197  inline const char *get(char *buffer) const {
198  return ucommon::DateTime::put(buffer);
199  }
200 
201  inline time_t getTime(void) const {
203  }
204 
205  inline bool isValid(void) const {
207  }
208 
209  inline int getHour(void) const {
210  return hour();
211  }
212 
213  inline int getMinute(void) const {
214  return minute();
215  }
216 
217  inline int getSecond(void) const {
218  return second();
219  }
220 
221  inline static tm_t *glt(time_t *time = NULL) {
222  return ucommon::DateTime::local(time);
223  }
224 };
225 
226 } // namespace ost
227 
228 #endif
229 
The Date class uses a julian date representation of the current year, month, and day.
Definition: datetime.h:79
bool is_valid(void) const
Test if object is valid.
The Datetime class uses a julian date representation of the current year, month, and day and a intege...
Definition: datetime.h:618
void set(void)
Set (update) the date with current date.
A number class that manipulates a string buffer that is also a date.
Definition: datetime.h:971
const char * put(char *buffer) const
Get a ISO formatted date and time string for current object.
Common C++ generic string class.
struct tm tm_t
Convenience type for struct tm.
Definition: datetime.h:62
Common namespace for all ucommon objects.
Definition: access.h:47
time_t timeref(void) const
Get a time_t for the julian date if in time_t epoch.
static tm_t * local(const time_t *time=NULL)
Fetch an instance of time converted to local time.
The Time class uses a integer representation of the current time.
Definition: datetime.h:351
A DateTime string class.
Definition: datetime.h:869