Beispiel #1
0
time_t fileglob_ConvertToTime_t(const FILETIME* fileTime) {
	SYSTEMTIME universalSystemTime;
	SYSTEMTIME sysTime;
	struct tm atm;

	FileTimeToSystemTime(fileTime, &universalSystemTime);

	if (!fnSystemTimeToTzSpecificLocalTime) {
		HMODULE aLib = LoadLibraryA("kernel32.dll");
		if (aLib == NULL)
			return 0;

		*(void**)&fnSystemTimeToTzSpecificLocalTime = (void*)GetProcAddress(aLib, "SystemTimeToTzSpecificLocalTime");
	}
	fnSystemTimeToTzSpecificLocalTime(NULL, &universalSystemTime, &sysTime);

	// then convert the system time to a time_t (C-runtime local time)
	if (sysTime.wYear < 1900) {
		return 0;
	}

	atm.tm_sec = sysTime.wSecond & ~1;		// Zip files are only accurate to 2 seconds.
	atm.tm_min = sysTime.wMinute;
	atm.tm_hour = sysTime.wHour;
	atm.tm_mday = sysTime.wDay;
	atm.tm_mon = sysTime.wMonth - 1;        // tm_mon is 0 based
	atm.tm_year = sysTime.wYear - 1900;     // tm_year is 1900 based
	atm.tm_isdst = -1;
	return mktime(&atm);
}
Beispiel #2
0
static void CalcTsOffset(MIM_TIMEZONE *tz)
{
	SYSTEMTIME st, stl;
	GetSystemTime(&st);

	FILETIME ft;
	SystemTimeToFileTime(&st, &ft);
	time_t ts1 = FileTimeToUnixTime(&ft);

	if (!fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &st, &stl))
		return;

	SystemTimeToFileTime(&stl, &ft);
	time_t ts2 = FileTimeToUnixTime(&ft);

	tz->offset = ts2 - ts1;
}
Beispiel #3
0
MIR_CORE_DLL(int) TimeZone_GetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st)
{
	if (st == NULL) return 1;

	MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ;
	if (tz == UTC_TIME_HANDLE)
		GetSystemTime(st);
	else if (tz && tz != &myInfo.myTZ) {
		SYSTEMTIME sto;
		GetSystemTime(&sto);
		return !fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &sto, st);
	}
	else
		GetLocalTime(st);

	return 0;
}