-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwtime.h
More file actions
320 lines (264 loc) · 7.04 KB
/
Copy pathwtime.h
File metadata and controls
320 lines (264 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#ifndef _INC_WTIME_
#define _INC_WTIME_
#include <windows.h>
#include <stdio.h>
// 1/10 µs between 1 Jan 1601 and 1 Jan 1900.
#define FILETIME_19000101 (94354848000000000)
#ifdef _M_ARM
#ifdef CharToOemA
#undef CharToOemA
#endif
#define CharToOemA(s,t)
#endif
#ifdef __cplusplus
// Enhanced FILETIME structure with encapsulated API functions,
// compare operators and type conversions
struct WFileTime : public FILETIME
{
// Get current time function
void GetUTC()
{
GetSystemTimeAsFileTime(this);
}
// Time compare operators
bool operator ==(CONST WFileTime &wft) const
{
return !CompareFileTime(this, &wft);
}
bool operator >(CONST WFileTime &wft) const
{
return CompareFileTime(this, &wft) > 0;
}
bool operator >=(CONST WFileTime &wft) const
{
return CompareFileTime(this, &wft) >= 0;
}
bool operator <(CONST WFileTime &wft) const
{
return CompareFileTime(this, &wft) < 0;
}
bool operator <=(CONST WFileTime& wft) const
{
return CompareFileTime(this, &wft) <= 0;
}
WFileTime operator +(CONST WFileTime& wft)
{
return *(LONGLONG*)this + *(LONGLONG*)&wft;
}
WFileTime operator -(CONST WFileTime& wft)
{
return *(LONGLONG*)this - *(LONGLONG*)&wft;
}
WFileTime& operator +=(CONST WFileTime& wft)
{
*(LONGLONG*)this += *(LONGLONG*)&wft;
return *this;
}
WFileTime& operator -=(CONST WFileTime& wft)
{
*(LONGLONG*)this -= *(LONGLONG*)&wft;
return *this;
}
// Convert to DOS FAT date and time
BOOL ToDOS(LPWORD lpFatDate, LPWORD lpFatTime) const
{
return FileTimeToDosDateTime(this, lpFatDate, lpFatTime);
}
BOOL ToLocal(LPFILETIME lpft) const
{
return FileTimeToLocalFileTime(this, lpft);
}
BOOL ToUTC(LPFILETIME lpft) const
{
return LocalFileTimeToFileTime(this, lpft);
}
// Type conversions
operator DWORDLONG() const
{
return *(DWORDLONG*)this;
}
// Type conversions
operator LONGLONG() const
{
return *(LONGLONG*)this;
}
// Constructors
WFileTime(CONST FILETIME &ft)
{
*(FILETIME*)this = ft;
}
WFileTime(CONST SYSTEMTIME &st)
{
SystemTimeToFileTime(&st, this);
}
// Construct from QWORD value
WFileTime(DWORDLONG qw)
{
*(DWORDLONG*)this = qw;
}
// Construct from QWORD value
WFileTime(LONGLONG qw)
{
*(LONGLONG*)this = qw;
}
bool IsZero() const
{
return (dwLowDateTime == 0) && (dwHighDateTime == 0);
}
void PrintAbsoluteTime()
{
DWORDLONG qwTime = *(DWORDLONG*)this;
double dblMilliseconds;
DWORD dwSeconds;
DWORD dwMinutes;
DWORD dwHours;
DWORD dwDays;
DWORD dwWeeks;
dwWeeks = (DWORD)(qwTime / 6048000000000); qwTime %= 6048000000000;
dwDays = (DWORD)(qwTime / 864000000000); qwTime %= 864000000000;
dwHours = (DWORD)(qwTime / 36000000000); qwTime %= 36000000000;
dwMinutes = (DWORD)(qwTime / 600000000); qwTime %= 600000000;
dwSeconds = (DWORD)(qwTime / 10000000); qwTime %= 10000000;
dblMilliseconds = (double)qwTime / 10000;
if (dwWeeks)
printf("%u weeks, ", dwWeeks);
if (dwDays)
printf("%u days, ", dwDays);
printf("%u:%.2u:%.2u %f",
dwHours, dwMinutes, dwSeconds, dblMilliseconds);
}
// Construct from DOS FAT date and time
WFileTime(WORD wFatDate, WORD wFatTime)
{
DosDateTimeToFileTime(wFatDate, wFatTime, this);
}
// Empty constructor
WFileTime()
{
*(DWORDLONG*)this = 0;
}
};
// Enhanced SYSTEMTIME structure with encapsulated API functions and type
// conversions
struct WSystemTime : public SYSTEMTIME
{
// Get/set current time functions
void GetLocal()
{
GetLocalTime(this);
}
void GetUTC()
{
GetSystemTime(this);
}
BOOL SetLocal() const
{
return SetLocalTime(this);
}
BOOL SetUTC() const
{
return SetSystemTime(this);
}
// Special for Windows NT
BOOL GetUTCAsTzSpecificLocal(LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
LPSYSTEMTIME lpUniversalTime)
{
return SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation,
lpUniversalTime, this);
}
VOID CDECL PrintShortDate(FILE *strm = stdout)
{
char cBuf[160];
if (GetDateFormatA(LOCALE_USER_DEFAULT, 0, this, NULL, cBuf, sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fputs(cBuf, strm);
}
}
VOID CDECL PrintLongDate(FILE *strm = stdout)
{
char cBuf[160];
if (GetDateFormatA(LOCALE_USER_DEFAULT, DATE_LONGDATE, this, NULL, cBuf,
sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fputs(cBuf, strm);
}
}
VOID CDECL PrintTime(FILE *strm = stdout)
{
char cBuf[160];
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, this, NULL, cBuf, sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fputs(cBuf, strm);
}
}
VOID CDECL PrintShortDateAndTime(FILE *strm = stdout)
{
char cBuf[160];
if (GetDateFormatA(LOCALE_USER_DEFAULT, 0, this, NULL, cBuf, sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fprintf(strm, "%s ", cBuf);
}
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, this, NULL, cBuf, sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fputs(cBuf, strm);
}
}
VOID CDECL PrintLongDateAndTime(FILE *strm = stdout)
{
char cBuf[160];
if (GetDateFormatA(LOCALE_USER_DEFAULT, DATE_LONGDATE, this, NULL, cBuf,
sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fprintf(strm, "%s ", cBuf);
}
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, this, NULL, cBuf, sizeof cBuf))
{
CharToOemA(cBuf, cBuf);
fputs(cBuf, strm);
}
}
// Constructors
WSystemTime(CONST SYSTEMTIME &st)
{
*(SYSTEMTIME*)this = st;
}
WSystemTime(CONST FILETIME &ft)
{
FileTimeToSystemTime(&ft, this);
}
WSystemTime()
{
ZeroMemory(this, sizeof *this);
}
};
// Enhanced TIME_ZONE_INFORMATION structure with encapsulated API functions
struct WTimeZoneInformation : public TIME_ZONE_INFORMATION
{
operator TIME_ZONE_INFORMATION() const
{
return *(TIME_ZONE_INFORMATION*)this;
}
DWORD Get()
{
return GetTimeZoneInformation(this);
}
BOOL Set() const
{
return SetTimeZoneInformation(this);
}
};
#else /* _cplusplus */
EXTERN_C VOID CDECL PrintShortDate(SYSTEMTIME*);
EXTERN_C VOID CDECL PrintLongDate(SYSTEMTIME*);
EXTERN_C VOID CDECL PrintTime(SYSTEMTIME*);
EXTERN_C VOID CDECL PrintShortDateAndTime(SYSTEMTIME*);
EXTERN_C VOID CDECL PrintLongDateAndTime(SYSTEMTIME*);
EXTERN_C VOID CDECL PrintAbsoluteTime(DWORDLONG);
#endif
#endif