Ejemplo n.º 1
0
FILETIME FileLib::getFileTime(SYSTEMTIME &systemTime, bool asLocalTimeZone) {
	FILETIME fileTime;

	if (asLocalTimeZone) {
		TIME_ZONE_INFORMATION tzInfo;
		const DWORD tzType = GetTimeZoneInformation(&tzInfo);
		if (tzType == TIME_ZONE_ID_INVALID) {
			UTIL_THROW_PLATFORM_ERROR(NULL);
		}
		SYSTEMTIME utcSystemTime;
		if (!TzSpecificLocalTimeToSystemTime(
				&tzInfo, &systemTime, &utcSystemTime)) {
			UTIL_THROW_PLATFORM_ERROR(NULL);
		}
		if (!SystemTimeToFileTime(&utcSystemTime, &fileTime)) {
			UTIL_THROW_PLATFORM_ERROR(NULL);
		}
	} else {
		if (!SystemTimeToFileTime(&systemTime, &fileTime)) {
			UTIL_THROW_PLATFORM_ERROR(NULL);
		}
	}

	return fileTime;
}
Ejemplo n.º 2
0
	bool FileSystem::SetFileEditDate(const String& path, const TimeStamp& time) const
	{
		FILETIME lastWriteTime;
		HANDLE hFile = CreateFileA(path.Data(), GENERIC_READ | FILE_WRITE_ATTRIBUTES,
								   FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
		if (hFile == NULL)
			return false;

		SYSTEMTIME stLocal, stUTC;

		stLocal.wSecond = time.mSecond;
		stLocal.wDayOfWeek = 0;
		stLocal.wMilliseconds = 0;
		stLocal.wMinute = time.mMinute;
		stLocal.wHour = time.mHour;
		stLocal.wDay = time.mDay;
		stLocal.wMonth = time.mMonth;
		stLocal.wYear = time.mYear;

		TzSpecificLocalTimeToSystemTime(NULL, &stLocal, &stUTC);
		SystemTimeToFileTime(&stUTC, &lastWriteTime);
		if (!SetFileTime(hFile, NULL, NULL, &lastWriteTime))
		{
			auto error = GetLastError();
			printf("err %i\n", error);
			CloseHandle(hFile);
			return false;
		}

		CloseHandle(hFile);

		return true;
	}
Ejemplo n.º 3
0
TimeValue System::LocalToUTCTime( TimeValue iLocalTime, TimeUnit iResolution, const TimeZone * pTimeZone ) const
{
    FILETIME hFlatTimeLocal;
    _RevertTimeValue( &hFlatTimeLocal, iLocalTime, iResolution );

    if ( pTimeZone == NULL ) {
        FILETIME hFlatTimeUTC;
        BOOL bRes = LocalFileTimeToFileTime( &hFlatTimeLocal, &hFlatTimeUTC );
        DebugAssert( bRes != FALSE );

        return _ConvertTimeValue( &hFlatTimeUTC, iResolution );
    } else {
        TIME_ZONE_INFORMATION hTimeZone;
        _RevertTimeZone( &hTimeZone, pTimeZone );

        SYSTEMTIME hSystemTimeLocal;
        BOOL bRes = FileTimeToSystemTime( &hFlatTimeLocal, &hSystemTimeLocal );
        DebugAssert( bRes != FALSE );

        SYSTEMTIME hSystemTimeUTC;
        bRes = TzSpecificLocalTimeToSystemTime( &hTimeZone, &hSystemTimeLocal, &hSystemTimeUTC );
        DebugAssert( bRes != FALSE );

        FILETIME hFlatTimeUTC;
        bRes = SystemTimeToFileTime( &hSystemTimeUTC, &hFlatTimeUTC );
        DebugAssert( bRes != FALSE );

        return _ConvertTimeValue( &hFlatTimeUTC, iResolution );
    }
}
Ejemplo n.º 4
0
DOUBLE TimeMake(SYSTEMTIME* stl, double tzo = 100.0)
{
	SYSTEMTIME stu;
	FILETIME ft;
	TIME_ZONE_INFORMATION tz;
	DOUBLE t = 0.0;
	if (tzo > 99.9) {
		GetTimeZoneInformation(&tz);
	} else {
		tz.Bias = (int)(tzo * 60.0);
		tz.DaylightDate.wMonth = tz.StandardDate.wMonth = 0;
		tz.DaylightBias = tz.StandardBias = 0;
		tz.DaylightName[0] = tz.StandardName[0] = 0;
	}
	if (TzSpecificLocalTimeToSystemTime(&tz, stl, &stu))
	{
		if (SystemTimeToFileTime(&stu, &ft))
		{
			ULARGE_INTEGER u; u.HighPart = ft.dwHighDateTime; u.LowPart = ft.dwLowDateTime;
			t = (DOUBLE)u.QuadPart;
			t /= 10000000;
			t /= (60 * 60 * 24);
		}
	}
	return t;
}
Ejemplo n.º 5
0
bool touchmind::util::TimeUtil::LocalSystemTime(SYSTEMTIME localSystemTime, SYSTEMTIME* systemTime)
{
    TIME_ZONE_INFORMATION timeZoneInfo;
    if (GetTimeZoneInformation(&timeZoneInfo) == TIME_ZONE_ID_INVALID) {
        return false;
    }

    if (TzSpecificLocalTimeToSystemTime(&timeZoneInfo, &localSystemTime, systemTime) == 0) {
        return false;
    }
    return true;
}
Ejemplo n.º 6
0
void RarTime::SetLocal(RarLocalTime *lt)
{
#ifdef _WIN_ALL
  SYSTEMTIME st;
  st.wYear=lt->Year;
  st.wMonth=lt->Month;
  st.wDay=lt->Day;
  st.wHour=lt->Hour;
  st.wMinute=lt->Minute;
  st.wSecond=lt->Second;
  st.wMilliseconds=0;
  st.wDayOfWeek=0;
  FILETIME lft;
  if (SystemTimeToFileTime(&st,&lft))
  {
    lft.dwLowDateTime+=lt->Reminder;
    if (lft.dwLowDateTime<lt->Reminder)
      lft.dwHighDateTime++;

    FILETIME ft;

    if (WinNT() < WNT_VISTA)
    {
      // TzSpecificLocalTimeToSystemTime based code produces 1 hour error on XP.
      LocalFileTimeToFileTime(&lft,&ft);
    }
    else
    {
      // Reverse procedure which we do in GetLocal.
      SYSTEMTIME st1,st2;
      FileTimeToSystemTime(&lft,&st2); // st2 might be unequal to st, because we added lt->Reminder to lft.
      TzSpecificLocalTimeToSystemTime(NULL,&st2,&st1);
      SystemTimeToFileTime(&st1,&ft);

      // Correct precision loss (low 4 decimal digits) in FileTimeToSystemTime.
      FILETIME rft;
      SystemTimeToFileTime(&st2,&rft);
      int64 Corrected=INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime)-
                      INT32TO64(rft.dwHighDateTime,rft.dwLowDateTime)+
                      INT32TO64(ft.dwHighDateTime,ft.dwLowDateTime);
      ft.dwLowDateTime=(DWORD)Corrected;
      ft.dwHighDateTime=(DWORD)(Corrected>>32);
    }

    *this=ft;
  }
Ejemplo n.º 7
0
Void System::LocalToUTCTime( TimeDate * outUTCTime, const TimeDate & hLocalTime, const TimeZone * pTimeZone ) const
{
    SYSTEMTIME hSystemTimeLocal;
    _RevertTimeDate( &hSystemTimeLocal, &hLocalTime );

    TIME_ZONE_INFORMATION hTimeZone;
    if ( pTimeZone == NULL )
        GetTimeZoneInformation( &hTimeZone );
    else    
        _RevertTimeZone( &hTimeZone, pTimeZone );

    SYSTEMTIME hSystemTimeUTC;
    BOOL bRes = TzSpecificLocalTimeToSystemTime( &hTimeZone, &hSystemTimeLocal, &hSystemTimeUTC );
    DebugAssert( bRes != FALSE );

    _ConvertTimeDate( outUTCTime, &hSystemTimeUTC );
}
Ejemplo n.º 8
0
void DiskFile::SetLastWriteTime(time_t lastWriteTime)
{
#if defined(PLATFORM_WINDOWS)
	FILETIME localFILETIME;
	LONGLONG ll = Int32x32To64(lastWriteTime, 10000000) + 116444736000000000;
	localFILETIME.dwLowDateTime = (DWORD) ll;
	localFILETIME.dwHighDateTime = (DWORD)(ll >>32);
	
	SYSTEMTIME localSystemTime;
	FileTimeToSystemTime(&localFILETIME, &localSystemTime);

	SYSTEMTIME universalSystemTime;
	TzSpecificLocalTimeToSystemTime(NULL, &localSystemTime, &universalSystemTime);

	FILETIME lastWriteTimeFILETIME;
	SystemTimeToFileTime(&localSystemTime, &lastWriteTimeFILETIME);

	if ( !::SetFileTime(m_fileHandle, NULL, NULL, &lastWriteTimeFILETIME) )
		return;
#else
	assert(0);
#endif

}
Ejemplo n.º 9
0
DateTime DateTime::to_utc() const
{
	throw_if_null();
	if (timezone == utc_timezone)
	{
		return *this;
	}
	else
	{
	#ifdef WIN32
		SYSTEMTIME local_time;
		SYSTEMTIME system_time;
		local_time.wYear = year;
		local_time.wMonth = month;
		local_time.wDay = day;
		local_time.wHour = hour;
		local_time.wMinute = minute;
		local_time.wSecond = seconds;
		local_time.wMilliseconds = nanoseconds / 1000000;
		#if _MSC_VER
		BOOL result = TzSpecificLocalTimeToSystemTime(0, &local_time, &system_time);
		#else
		BOOL result = SystemTimeToTzSpecificLocalTime(0, &system_time, &local_time);
		#endif
		if (result == FALSE)
			throw Exception("TzSpecificLocalTimeToSystemTime failed");

		DateTime datetime;
		datetime.timezone = utc_timezone;
		datetime.year = system_time.wYear;
		datetime.month = system_time.wMonth;
		datetime.day = system_time.wDay;
		datetime.hour = system_time.wHour;
		datetime.minute = system_time.wMinute;
		datetime.seconds = system_time.wSecond;
		datetime.nanoseconds = system_time.wMilliseconds * 1000000;
		datetime.nanoseconds += (nanoseconds % 1000000);
		return datetime;
	#else
		tm tm_local;
		memset(&tm_local, 0, sizeof(tm));
		tm_local.tm_year = year-1900;
		tm_local.tm_mon = month-1;
		tm_local.tm_mday = day;
		tm_local.tm_hour = hour;
		tm_local.tm_min = minute;
		tm_local.tm_sec = seconds;
		tm_local.tm_isdst = -1;
		time_t unix_ticks = mktime(&tm_local);
		if (unix_ticks == -1)
			throw Exception("mktime failed");

		memset(&tm_local, 0, sizeof(tm));
		tm *result = gmtime_r(&unix_ticks, &tm_local);
		if (result == nullptr)
			throw Exception("gmtime_r failed");

		DateTime datetime;
		datetime.timezone = utc_timezone;
		datetime.year = result->tm_year+1900;
		datetime.month = result->tm_mon+1;
		datetime.day = result->tm_mday;
		datetime.hour = result->tm_hour;
		datetime.minute = result->tm_min;
		datetime.seconds = result->tm_sec;
		datetime.nanoseconds = nanoseconds;
		return datetime;
	#endif
	}
}
Ejemplo n.º 10
0
dng_time_zone LocalTimeZone (const dng_date_time &dt)
	{
	
	dng_time_zone result;
	
	if (dt.IsValid ())
		{
		
		#if qMacOS
		
		CFTimeZoneRef zoneRef = CFTimeZoneCopyDefault ();
		
		if (zoneRef)
			{
			
			CFGregorianDate gregDate;

			gregDate.year   = dt.fYear;
			gregDate.month  = dt.fMonth;
			gregDate.day    = dt.fDay;
			gregDate.hour   = dt.fHour;
			gregDate.minute = dt.fMinute;
			gregDate.second = dt.fSecond;
			
			CFAbsoluteTime absTime = CFGregorianDateGetAbsoluteTime (gregDate, zoneRef);
			
			CFTimeInterval secondsDelta = CFTimeZoneGetSecondsFromGMT (zoneRef, absTime);
		
			CFRelease (zoneRef);
			
			result.SetOffsetSeconds (secondsDelta);
			
			if (result.IsValid ())
				{
				return result;
				}
			
			}
		
		#endif
		
		#if qWinOS
		
		if (GetTimeZoneInformation          != NULL &&
			SystemTimeToTzSpecificLocalTime != NULL &&
		    SystemTimeToFileTime            != NULL)
			{
			
			TIME_ZONE_INFORMATION tzInfo;
			
			DWORD x = GetTimeZoneInformation (&tzInfo);
			
			SYSTEMTIME localST;
			
			memset (&localST, 0, sizeof (localST));

			localST.wYear   = (WORD) dt.fYear;
			localST.wMonth  = (WORD) dt.fMonth;
			localST.wDay    = (WORD) dt.fDay;
			localST.wHour   = (WORD) dt.fHour;
			localST.wMinute = (WORD) dt.fMinute;
			localST.wSecond = (WORD) dt.fSecond;
			
			SYSTEMTIME utcST;

			if (TzSpecificLocalTimeToSystemTime (&tzInfo, &localST, &utcST))
				{
				
				FILETIME localFT;
				FILETIME utcFT;
				
				(void) SystemTimeToFileTime (&localST, &localFT);
				(void) SystemTimeToFileTime (&utcST  , &utcFT  );
				
				uint64 time1 = (((uint64) localFT.dwHighDateTime) << 32) + localFT.dwLowDateTime;
				uint64 time2 = (((uint64) utcFT  .dwHighDateTime) << 32) + utcFT  .dwLowDateTime;
				
				// FILETIMEs are in units to 100 ns.  Convert to seconds.
				
				int64 time1Sec = time1 / 10000000;
				int64 time2Sec = time2 / 10000000;
			
				int32 delta = (int32) (time1Sec - time2Sec);

				result.SetOffsetSeconds (delta);
					
				if (result.IsValid ())
					{
					return result;
					}
			
				}
			
			}
		
		#endif
		
		}
	
	// Figure out local time zone.
	
	dng_date_time_info current_info;
	
	CurrentDateTimeAndZone (current_info);
	
	result = current_info.TimeZone ();
		
	return result;
			
	}