#include "Basic.h"
#include <time.h>
#if defined VCZH_MSVC
#include <Windows.h>
#elif defined VCZH_GCC
#include <memory.h>
#include <sys/time.h>
#endif
namespace
{
::
()
{
}
::
(
const
&)
{
}
&
::
(
const
&)
{
return
*
this
;
}
::
(
const
wchar_t
*
)
{
=
;
}
const
wchar_t
*
::
()
const
{
return
;
}
::
()
{
}
#if defined VCZH_MSVC
(
const
&
)
{
;
dateTime
.
=
.
;
dateTime
.
=
.
;
dateTime
.
=
.
;
dateTime
.
=
.
;
dateTime
.
=
.
;
dateTime
.
=
.
;
dateTime
.
=
.
;
dateTime
.
=
.
;
;
(&
, &
fileTime
);
;
largeInteger
.
=
fileTime
.
;
largeInteger
.
=
fileTime
.
;
dateTime
.
=
largeInteger
.
;
dateTime
.
=
dateTime
.
/
10000
;
return
dateTime
;
}
(
const
&
)
{
;
largeInteger
.
=
.
;
;
fileTime
.
=
largeInteger
.
;
fileTime
.
=
largeInteger
.
;
;
(&
fileTime
, &
systemTime
);
return
systemTime
;
}
#elif defined VCZH_GCC
DateTime ConvertTMToDateTime(tm* timeinfo, vint milliseconds)
{
time_t timer = mktime(timeinfo);
DateTime dt;
dt.year = timeinfo->tm_year+1900;
dt.month = timeinfo->tm_mon+1;
dt.day = timeinfo->tm_mday;
dt.dayOfWeek = timeinfo->tm_wday;
dt.hour = timeinfo->tm_hour;
dt.minute = timeinfo->tm_min;
dt.second = timeinfo->tm_sec;
dt.milliseconds = milliseconds;
// in Linux and macOS, filetime will be mktime(t) * 1000 + gettimeofday().tv_usec / 1000
dt.filetime = (vuint64_t)timer * 1000 + milliseconds;
dt.totalMilliseconds = (vuint64_t)timer * 1000 + milliseconds;
return dt;
}
#endif
::
()
{
#if defined VCZH_MSVC
;
(&
systemTime
);
return
(
systemTime
);
#elif defined VCZH_GCC
struct timeval tv;
gettimeofday(&tv, nullptr);
tm* timeinfo = localtime(&tv.tv_sec);
return ConvertTMToDateTime(timeinfo, tv.tv_usec / 1000);
#endif
}
::
()
{
#if defined VCZH_MSVC
;
(&
utcTime
);
return
(
utcTime
);
#elif defined VCZH_GCC
struct timeval tv;
gettimeofday(&tv, nullptr);
tm* timeinfo = gmtime(&tv.tv_sec);
return ConvertTMToDateTime(timeinfo, tv.tv_usec / 1000);
#endif
}
::
(
,
,
,
,
,
,
)
{
#if defined VCZH_MSVC
;
(&
systemTime
,
0
,
sizeof
(
systemTime
));
systemTime
.
=(
)
;
systemTime
.
=(
)
;
systemTime
.
=(
)
;
systemTime
.
=(
)
;
systemTime
.
=(
)
;
systemTime
.
=(
)
;
systemTime
.
=(
)
;
;
(&
systemTime
, &
fileTime
);
(&
fileTime
, &
systemTime
);
return
(
systemTime
);
#elif defined VCZH_GCC
tm timeinfo;
memset(&timeinfo, 0, sizeof(timeinfo));
timeinfo.tm_year = _year-1900;
timeinfo.tm_mon = _month-1;
timeinfo.tm_mday = _day;
timeinfo.tm_hour = _hour;
timeinfo.tm_min = _minute;
timeinfo.tm_sec = _second;
timeinfo.tm_isdst = -1;
return ConvertTMToDateTime(&timeinfo, _milliseconds);
#endif
}
::
(
)
{
#if defined VCZH_MSVC
;
largeInteger
.
=
;
;
fileTime
.
=
largeInteger
.
;
fileTime
.
=
largeInteger
.
;
;
(&
fileTime
, &
systemTime
);
return
(
systemTime
);
#elif defined VCZH_GCC
time_t timer = (time_t)(filetime / 1000);
tm* timeinfo = localtime(&timer);
return ConvertTMToDateTime(timeinfo, filetime % 1000);
#endif
}
::
()
:year(
0
)
,month(
0
)
,day(
0
)
,hour(
0
)
,minute(
0
)
,second(
0
)
,milliseconds(
0
)
,filetime(
0
)
{
}
::
()
{
#if defined VCZH_MSVC
=
(*
this
);
;
SystemTimeToTzSpecificLocalTime(NULL, &utcTime, &localTime);
SystemTimeToTzSpecificLocalTime
(
0
, &
utcTime
, &
localTime
);
return
(
localTime
);
#elif defined VCZH_GCC
time_t localTimer = time(nullptr);
time_t utcTimer = mktime(gmtime(&localTimer));
time_t timer = (time_t)(filetime / 1000) + localTimer - utcTimer;
tm* timeinfo = localtime(&timer);
return ConvertTMToDateTime(timeinfo, milliseconds);
#endif
}
::
()
{
#if defined VCZH_MSVC
=
(*
this
);
;
TzSpecificLocalTimeToSystemTime(NULL, &localTime, &utcTime);
TzSpecificLocalTimeToSystemTime
(
0
, &
localTime
, &
utcTime
);
return
(
utcTime
);
#elif defined VCZH_GCC
time_t timer = (time_t)(filetime / 1000);
tm* timeinfo = gmtime(&timer);
return ConvertTMToDateTime(timeinfo, milliseconds);
#endif
}
::
(
)
{
#if defined VCZH_MSVC
return
(
+
*
10000
);
#elif defined VCZH_GCC
return FromFileTime(filetime+milliseconds);
#endif
}
::
(
)
{
#if defined VCZH_MSVC
return
(
-
*
10000
);
#elif defined VCZH_GCC
return FromFileTime(filetime-milliseconds);
#endif
}
::
()
{
}
}