forked from EgeBalci/Zeus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.cpp
71 lines (56 loc) · 1.37 KB
/
time.cpp
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
#include <windows.h>
#include "math.h"
#include "time.h"
void Time::init(void)
{
}
void Time::uninit(void)
{
}
DWORD Time::_getTime(void)
{
SYSTEMTIME st;
CWA(kernel32, GetSystemTime)(&st);
return _systemTimeToTime(&st);
}
DWORD Time::_getLocalTime(void)
{
return _getTime() + _getLocalGmt();
}
int Time::_getLocalGmt(void)
{
TIME_ZONE_INFORMATION tzi;
int d = (int)CWA(kernel32, GetTimeZoneInformation)(&tzi);
if(d == TIME_ZONE_ID_STANDARD)d = tzi.StandardBias;
else if(d == TIME_ZONE_ID_DAYLIGHT)d = tzi.DaylightBias;
else return 0;
return (tzi.Bias + d) * (-60);
}
DWORD Time::_fileTimeToTime(const FILETIME *ft)
{
//WARN: look FILETIME for more information.
register DWORD64 tim = (DWORD64)(*((DWORD64 *)ft) - 116444736000000000i64);
#if defined _WIN64
tim /= 10000000;
#else
tim = Math::_divU64(tim, 10000000);
#endif
return (DWORD)tim;
}
void Time::_timeToFileTime(const DWORD time, FILETIME *ft)
{
register DWORD64 tim = 116444736000000000i64;
#if defined _WIN64
tim += time * 10000000;
#else
tim += Math::_mul64(time, 10000000);
#endif
//WARN: look FILETIME for more information.
*((DWORD64 *)ft) = tim;
}
DWORD Time::_systemTimeToTime(const SYSTEMTIME *st)
{
FILETIME ft;
CWA(kernel32, SystemTimeToFileTime)((SYSTEMTIME *)st, &ft);
return _fileTimeToTime(&ft);
}