-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeTools.cpp
68 lines (57 loc) · 1.45 KB
/
TimeTools.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
#include "TimeTools.h"
//#ifdef WIN32
//// Should be built with /clr
//#using <mscorlib.dll>
//#endif
TOOLSPACE_BEGIN
DString TimeTools::m_strZoneInfo = "";
bool TimeTools::getLocalTZOffset(DFloat8 & out_iTZOffset)
{
out_iTZOffset = 0;
bool tmp_bFlag = false;
#ifdef _BSD_SOURCE
struct tm tmp_tmBase;
tmp_tmBase.tm_year = 1970 - 1900; // years since 1900
tmp_tmBase.tm_mon = 1 - 1; // months since January 0-11
tmp_tmBase.tm_mday = 1;
tmp_tmBase.tm_hour = 0;
tmp_tmBase.tm_min = 0;
tmp_tmBase.tm_sec = 0;
time_t tmp_tLocalTime = 0;
// Thread safe
tmp_bFlag = true;
if ( NULL == localtime_r(&tmp_tLocalTime, &tmp_tmBase))
{
return false;
}
out_iTZOffset = tmp_tmBase.tm_gmtoff;
#endif
#ifdef WIN32
tmp_bFlag = true;
struct tm t1, t2;
time_t now, mytime, gmtime;
time( & now );
_localtime64_s( &t1, &now );
_localtime64_s( &t2, &now );
mytime = mktime(&t1);
gmtime = _mkgmtime(&t2);
out_iTZOffset = static_cast<DFloat8>(gmtime - mytime);
#endif
return tmp_bFlag;
}
void TimeTools::setZoneinfoPath(const DString & in_strPath)
{
m_strZoneInfo = in_strPath;
}
bool TimeTools::getTZOffsetByZonename( const DString & in_strZoneName, DFloat8 & out_iTZOffset )
{
// TODO (dragonkid#1#): This Function will be complete later.
return true;
}
DTime_t TimeTools::getMilliTime()
{
timeb t;
ftime(&t);
return (1000 * static_cast<DTime_t>(t.time) + t.millitm);
}
TOOLSPACE_END