| MikroCAD SDK Library

- Home
- All Types
- Files

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
DateTime.h
Go to the documentation of this file.
1 /**
2 * @file DateTime.h
3 * @brief Date / Time functions
4 *
5 * @author LMI Technologies
6 */
7
8 #ifndef _DateTime_h
9 #define _DateTime_h
10
11 #include "Windows.h"
12 #include <string>
13
14 using namespace std;
15
16 /**
17 Standard date format
18 */
19 enum eDateFormat
20 {
21 DateFormat_Short, /**< Short format */
22 DateFormat_Long, /**< Long format */
23 };
24
25 /**
26 Standard time format
27 */
28 enum eTimeFormat
29 {
30 TimeFormat_Short, /**< Short format */
31 TimeFormat_Long, /**< Long format */
32 };
33
34 #define DATE_TIME_BUFFER_SIZE 512
35
36 /**
37 DateTime class
38 */
39 class CDateTime
40 {
41 public:
42
43 /**
44 Standard constructor
45 */
46 CDateTime();
47
48 /**
49 Constructor with date
50
51 @param dwDate Date
52 */
53 CDateTime(DWORD dwDate);
54
55 /**
56 Constructor with date time
57
58 @param ulDateTime Date time
59 */
60 CDateTime(ULONGLONG ulDateTime);
61
62 /**
63 Constructor with year, month, day
64
65 @param wYear Year
66 @param wMonth Month
67 @param wDay Day
68 */
69 CDateTime(WORD wYear, WORD wMonth, WORD wDay);
70
71 /**
72 Constructor with year, month, day, hour, minute, second, hundredth second
73
74 @param wYear Year
75 @param wMonth Month
76 @param wDay Day
77 @param wHour Hour
78 @param wMin Minute
79 @param wSec Second
80 @param wSec100 Hundredth second
81 */
82 CDateTime(WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMin, WORD wSec = 0, WORD wSec100 = 0);
83
84 /**
85 Initialize
86 */
87 void Initialize();
88
89 /**
90 Initialize with date
91
92 @param dwDate Date
93 */
94 void Initialize(DWORD dwDate);
95
96 /**
97 Initialize with date time
98
99 @param ulDateTime Date time
100 */
101 void Initialize(ULONGLONG ulDateTime);
102
103 /**
104 Initialize with year, month, day
105
106 @param wYear Year
107 @param wMonth Month
108 @param wDay Day
109 */
110 void Initialize(WORD wYear, WORD wMonth, WORD wDay);
111
112 /**
113 Initialize with year, month, day, hour, minute, second, hundredth second
114
115 @param wYear Year
116 @param wMonth Month
117 @param wDay Day
118 @param wHour Hour
119 @param wMin Minute
120 @param wSec Second
121 @param wSec100 Hundredth second
122 */
123 void Initialize(WORD wYear, WORD wMonth, WORD wDay, WORD wHour, WORD wMin, WORD wSec = 0, WORD wSec100 = 0);
124
125 /**
126 Get day
127 */
128 WORD GetDay()
129 {
130 return m_DateTime.wDay;
131 };
132
133 /**
134 Get Month
135 */
136 WORD GetMonth()
137 {
138 return m_DateTime.wMonth;
139 };
140
141 /**
142 Get year
143 */
144 WORD GetYear()
145 {
146 return m_DateTime.wYear;
147 };
148
149 /**
150 Get hour
151 */
152 WORD GetHour()
153 {
154 return m_DateTime.wHour;
155 };
156
157 /**
158 Get minute
159 */
160 WORD GetMinute()
161 {
162 return m_DateTime.wMinute;
163 };
164
165 /**
166 Get second
167 */
168 WORD GetSecond()
169 {
170 return m_DateTime.wSecond;
171 };
172
173 /**
174 Get hundredth second
175 */
176 WORD GetHundredthSecond()
177 {
178 return (WORD)(m_DateTime.wMilliseconds / 10);
179 };
180
181 /**
182 Date as string
183
184 @param Format Pre-defined format
185 @return Date as string
186 */
187 wstring DateString(eDateFormat Format);
188
189 /**
190 Date as string
191
192 @param stFormat User-defined format
193 @return Date as string
194 */
195 wstring DateString(wstring stFormat);
196
197 /**
198 Time as string
199
200 @param Format Pre-defined format
201 @return Time as string
202 */
203 wstring TimeString(eTimeFormat Format);
204
205 /**
206 Time as string
207
208 @param stFormat User-defined format
209 @return Time as string
210 */
211 wstring TimeString(wstring stFormat);
212
213 /**
214 Is year a leap year
215
216 @param wYear Year
217 @return Is leap year
218 */
219 static bool IsLeapYear(WORD wYear);
220
221 /**
222 Get current date time
223 */
224 static CDateTime Now();
225
226 /**
227 Convert DWORD to Date time object (time is unconsidered)
228
229 @param dwDate Date
230 @return new DateTime object
231 */
232 static CDateTime DateFromBinary(DWORD dwDate);
233
234 /**
235 Convert Date time object to DWORD (time is unconsidered)
236
237 @param DateTime DateTime object
238 @return DateTime as DWORD
239 */
240 static DWORD DateAsBinary(CDateTime& DateTime);
241
242 /**
243 Convert Date time to standard string(time is unconsidered)
244
245 @param DateTime DateTime object
246 @return DateTime as string
247 */
248 static wstring DateAsStandardString(CDateTime& DateTime);
249
250 /**
251 Convert standard string to Date time object to DWORD (time is unconsidered)
252
253 @param stDate Date as standard string
254 @param Date Output date
255 @return Success
256 */
257 static bool DateFromStandardString(wstring stDate, CDateTime& Date);
258
259 /**
260 Convert standard string to Date time object to DWORD
261
262 @param stDateTime Date and time as standard string
263 @param DateTime Output date
264 @return Success
265 */
266 static bool DateTimeFromStandardString(wstring stDateTime, CDateTime& DateTime);
267
268 /**
269 Convert ULONGLONG to DateTime object (time is unconsidered)
270
271 @param ulDateTime Date as ULONGLONG
272 @return new DateTime object
273 */
274 static CDateTime DateTimeFromBinary(ULONGLONG ulDateTime);
275
276 /**
277 Convert DateTime object to ULONGLONG (time is unconsidered)
278
279 @param DateTime Date Time
280 @return DateTime as ULONGLONG
281 */
282 static ULONGLONG DateTimeAsBinary(CDateTime& DateTime);
283
284 /**
285 Convert DateTime object to standard wide string (time is unconsidered)
286
287 @param DateTime Date Time
288 @return DateTime as string
289 */
290 static wstring DateTimeAsStandardString(CDateTime& DateTime);
291
292 /**
293 Convert DateTime object to standard string (time is unconsidered)
294
295 @param DateTime Date Time
296 @return DateTime as string
297 */
298 static string DateTimeAsStandardStringA(CDateTime& DateTime);
299
300 /**
301 Convert DateTime object to double
302
303 @param DateTime Date Time
304 @return DateTime as double
305 */
306 static double DateTimeAsDouble(CDateTime& DateTime);
307
308 /**
309 Copy operator
310 */
311 CDateTime& operator =(const CDateTime& DateTime);
312
313 private:
314
315 // Numbers of days in month
316 WORD DaysOfMonth(WORD wYear, WORD wMonth);
317
318 // Date from a DWORD
319 void DateFromDWord(DWORD dwDate);
320
321 // Date as DWORD
322 DWORD DateAsDWord();
323
324 /// Date time from ULONGLONG
325 void DateTimeFromULL(ULONGLONG ulDateTime);
326
327 // Date time as ULONGLONG
328 ULONGLONG DateTimeAsULL();
329
330 SYSTEMTIME m_DateTime;
331 wchar_t m_szBuffer[DATE_TIME_BUFFER_SIZE + 1];
332 };
333
334 #endif // _DateTime_h
DateFormat_Long
Long format.
Definition: DateTime.h:22
CDateTime::GetYear
WORD GetYear()
Get year.
Definition: DateTime.h:144
eTimeFormat
eTimeFormat
Standard time format.
Definition: DateTime.h:28
TimeFormat_Long
Long format.
Definition: DateTime.h:31
std
CDateTime::GetDay
WORD GetDay()
Get day.
Definition: DateTime.h:128
CDateTime::GetSecond
WORD GetSecond()
Get second.
Definition: DateTime.h:168
DateFormat_Short
Short format.
Definition: DateTime.h:21
CDateTime::GetHundredthSecond
WORD GetHundredthSecond()
Get hundredth second.
Definition: DateTime.h:176
eDateFormat
eDateFormat
Standard date format.
Definition: DateTime.h:19
CDateTime::GetHour
WORD GetHour()
Get hour.
Definition: DateTime.h:152
TimeFormat_Short
Short format.
Definition: DateTime.h:30
CDateTime::GetMinute
WORD GetMinute()
Get minute.
Definition: DateTime.h:160
CDateTime::GetMonth
WORD GetMonth()
Get Month.
Definition: DateTime.h:136
CDateTime
DateTime class.
Definition: DateTime.h:39