コード例 #1
0
ファイル: FileSystemImpl.cpp プロジェクト: zenkovich/o2
	FileInfo FileSystem::GetFileInfo(const String& path) const
	{
		FileInfo res;
		res.path = "invalid_file";

		FILETIME creationTime, lastAccessTime, lastWriteTime;
		HANDLE hFile = CreateFileA(path.Data(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
		if (hFile == NULL || hFile == INVALID_HANDLE_VALUE)
		{
			auto err = GetLastError();
			return res;
		}

		if (!GetFileTime(hFile, &creationTime, &lastAccessTime, &lastWriteTime))
		{
			CloseHandle(hFile);
			return res;
		}

		SYSTEMTIME stUTC, stLocal;

		FileTimeToSystemTime(&creationTime, &stUTC);
		SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
		res.createdDate = TimeStamp(stLocal.wSecond, stLocal.wMinute, stLocal.wHour, stLocal.wDay, stLocal.wMonth, stLocal.wYear);

		FileTimeToSystemTime(&lastAccessTime, &stUTC);
		SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
		res.accessDate = TimeStamp(stLocal.wSecond, stLocal.wMinute, stLocal.wHour, stLocal.wDay, stLocal.wMonth, stLocal.wYear);

		FileTimeToSystemTime(&lastWriteTime, &stUTC);
		SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
		res.editDate = TimeStamp(stLocal.wSecond, stLocal.wMinute, stLocal.wHour, stLocal.wDay, stLocal.wMonth, stLocal.wYear);

		res.path = path;
		String extension = path.SubStr(path.FindLast(".") + 1);
		res.fileType = FileType::File;

		for (auto iext : mInstance->mExtensions)
		{
			if (iext.Value().Contains(extension))
			{
				res.fileType = iext.Key();
				break;
			}
		}

		DWORD dwSizeHigh = 0, dwSizeLow = 0;
		dwSizeLow = GetFileSize(hFile, &dwSizeHigh);
		res.size = (dwSizeHigh * (MAXDWORD+1)) + dwSizeLow;

		CloseHandle(hFile);

		return res;
	}
コード例 #2
0
ファイル: layout_type_dated_local.c プロジェクト: Unidata/LDM
static const char* dated_local_format(
    const log4c_layout_t*  	a_layout,
    const log4c_logging_event_t*a_event)
{
    static char buffer[1024];

#ifdef LOG4C_POSIX_TIMESTAMP
    struct tm tm;
    time_t t;

    t = a_event->evt_timestamp.tv_sec;
    localtime_r(&t, &tm);
    snprintf(buffer, sizeof(buffer), "%04d%02d%02d %02d:%02d:%02d.%03ld %-8s %s- %s\n",
             tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
             tm.tm_hour, tm.tm_min, tm.tm_sec,
             a_event->evt_timestamp.tv_usec / 1000,
             log4c_priority_to_string(a_event->evt_priority),
             a_event->evt_category, a_event->evt_msg);
#else
    SYSTEMTIME stime, ltime;

    if (FileTimeToSystemTime(&a_event->evt_timestamp, &stime) &&
        SystemTimeToTzSpecificLocalTime(NULL, &stime, &ltime)) {
        snprintf(buffer, sizeof(buffer), "%04d%02d%02d %02d:%02d:%02d.%03ld %-8s %s- %s\n",
                 ltime.wYear, ltime.wMonth , ltime.wDay,
                 ltime.wHour, ltime.wMinute, ltime.wSecond,
                 ltime.wMilliseconds,
                 log4c_priority_to_string(a_event->evt_priority),
                 a_event->evt_category, a_event->evt_msg);
    }
#endif
    return buffer;
}
コード例 #3
0
stdstr CMainMenu::GetFileLastMod (stdstr FileName)
{
	HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_READ, FILE_SHARE_READ,NULL,
		OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
	if (hFile == INVALID_HANDLE_VALUE) 
	{
		return "";
	}
	FILETIME CreationTime, LastAccessTime, LastWriteTime;
	stdstr LastMod;
	if (GetFileTime(hFile,&CreationTime,&LastAccessTime,&LastWriteTime))
	{
		SYSTEMTIME stUTC, stLocal;

		 // Convert the last-write time to local time.
		FileTimeToSystemTime(&LastWriteTime, &stUTC);
		SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
		
		LastMod.Format(" [%d/%02d/%02d %02d:%02d]",
			stLocal.wYear, stLocal.wMonth, stLocal.wDay,stLocal.wHour, stLocal.wMinute);
	}
	CloseHandle(hFile);

	return LastMod;
}
コード例 #4
0
void MAPIAppointment::SetEndDate(FILETIME ft, bool bAllday)
{
    SYSTEMTIME st, localst;
    BOOL bUseLocal = false;

    FileTimeToSystemTime(&ft, &st);

    if (bAllday)    // if AllDay appt, subtract one from the end date for Zimbra friendliness
    {
	double dat = -1;
	if (SystemTimeToVariantTime(&st, &dat))
	{
	    dat -= 1;
	    VariantTimeToSystemTime(dat, &st);
	}
    }
    else
    {
	if ((m_bIsRecurring) || (m_iExceptionType == NORMAL_EXCEPTION))
	{
	    TIME_ZONE_INFORMATION localTimeZone = {0};
	    //GetTimeZoneInformation(&localTimeZone);	
		pInvTz->PopulateTimeZoneInfo(localTimeZone);
	    bUseLocal = SystemTimeToTzSpecificLocalTime(&localTimeZone, &st, &localst);
	}
    }
    m_pEndDate = (bUseLocal) ? Zimbra::Util::FormatSystemTime(localst, FALSE, TRUE)
			     : Zimbra::Util::FormatSystemTime(st, TRUE, TRUE);
}
コード例 #5
0
CString FiletimeAsString(FILETIME filetime)
{
	SYSTEMTIME sysTime;
	if(0 == FileTimeToSystemTime(&filetime,&sysTime))
		return _T("");

	SYSTEMTIME localTime;

	TIME_ZONE_INFORMATION tzi;
	GetTimeZoneInformation(&tzi);
	
	if (!SystemTimeToTzSpecificLocalTime(&tzi, &sysTime, &localTime))
		return _T("");

	CString sDate;
	TCHAR szDateBuffer[20] = {0};
	TCHAR szTimeBuffer[20] = {0};

	if (0 == GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &localTime, NULL, szDateBuffer, 20) ||
	    0 == GetTimeFormat(LOCALE_USER_DEFAULT, 0, &localTime, NULL, szTimeBuffer, 20))
		return _T("");

	sDate.Format(_T("%s %s"), szDateBuffer, szTimeBuffer);

   if(-1 != sDate.Find(_T("1601")))
      return _T("");

	return sDate;
}
コード例 #6
0
ファイル: liveshift.cpp プロジェクト: gfisher2/pvr.nextpvr
void LiveShiftSource::LOG(char const *fmt, ... )
{
  if (m_log != NULL)
  {
#if defined(TARGET_WINDOWS)
    // determine the current local time
    SYSTEMTIME utcSystemTime;
    GetSystemTime(&utcSystemTime);
    SYSTEMTIME systemTime;
    SystemTimeToTzSpecificLocalTime(NULL, &utcSystemTime, &systemTime);
    
    // log nicely formatted log message
    fprintf(m_log, "%02d:%02d:%02d.%03d\t", systemTime.wHour, systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds);

    // log passed-in string
    va_list ap; 
    va_start (ap, fmt); 
    vfprintf(m_log, fmt, ap); 
    va_end(ap); 

    fflush(m_log);
#else
    // log passed-in string
    va_list ap; 
    va_start (ap, fmt); 
    vfprintf(m_log, fmt, ap); 
    va_end(ap); 

    fflush(m_log);
#endif
  }
} 
コード例 #7
0
bool CAdminPageThreadWnd::VariantTimeToLocalTime(DATE date, SYSTEMTIME* psystime)
{
  // Convert the VARIANT time to a SYSTEMTIME structure
  SYSTEMTIME systimeUTC, systime;
  if (!VariantTimeToSystemTime(date, &systimeUTC))
    return false;

  // Convert the SYSTEMTIME from UTC to the local time zone
  if (!SystemTimeToTzSpecificLocalTime(NULL, &systimeUTC, &systime))
  {
    TIME_ZONE_INFORMATION tz;
    DWORD zone = GetTimeZoneInformation(&tz);
    if (zone != TIME_ZONE_ID_UNKNOWN)
    {
      LONG lBias = tz.Bias;
      if (zone == TIME_ZONE_ID_STANDARD)
        lBias += tz.StandardBias;
      else //TIME_ZONE_ID_DAYLIGHT:
        lBias += tz.DaylightBias;

      FILETIME ft;
      VERIFY(SystemTimeToFileTime(&systimeUTC, &ft));
      __int64 time64 = ((__int64)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
      __int64 bias = (__int64)lBias * (__int64)600000000;
      time64 -= bias;
      ft.dwHighDateTime = (DWORD)(time64 >> 32);
      ft.dwLowDateTime = (DWORD)time64;
      VERIFY(FileTimeToSystemTime(&ft,&systime));
    }
コード例 #8
0
void static update_win32_file_time(bt_ftp_obj_info_struct *ftp_file_info) {
    HANDLE hFile;
    FILETIME ftCreate, ftAccess, ftWrite;
    SYSTEMTIME stUTC, stLocal;

    hFile = CreateFileW( (const U16 *)ftp_file_info->file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        //printf("CreateFile failed with %d\n", GetLastError());
        return;
    }
    // Retrieve the file times for the file.
    if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite)) {
        CloseHandle(hFile);
        return;
    }

    // Convert the last-write time to local time.
    FileTimeToSystemTime(&ftWrite, &stUTC);
    SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

    ftp_file_info->year = stLocal.wYear;
    ftp_file_info->month = (U8) stLocal.wMonth;
    ftp_file_info->day = (U8) stLocal.wDay;
    ftp_file_info->hour = (U8) stLocal.wHour;
    ftp_file_info->min = (U8) stLocal.wMinute;
    ftp_file_info->sec = (U8) stLocal.wSecond;

    CloseHandle(hFile);
}
コード例 #9
0
int _GetFileTime(const char *fileName, char *lpszString, long dwSize) {
  BOOL fOk;
  WIN32_FILE_ATTRIBUTE_DATA fileInfo;
  SYSTEMTIME stUTC, stLocal;
  DWORD dwRet;

  if (NULL == fileName)
    return FALSE;

  fOk = GetFileAttributesEx(fileName, GetFileExInfoStandard, (void *)&fileInfo);
  if (!fOk)
    return FALSE;


  // Convert the last-write time to local time.
  FileTimeToSystemTime(&fileInfo.ftLastWriteTime, &stUTC);
  SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

  // Build a string showing the date and time.
  dwRet = sprintf_s(lpszString, dwSize,
                    TEXT("%02d/%02d/%d  %02d:%02d"),
                    stLocal.wMonth, stLocal.wDay, stLocal.wYear, stLocal.wHour, stLocal.wMinute);

  if (S_OK == dwRet)
    return TRUE;
  else
    return FALSE;
}                               /* _GetFileTime() */
コード例 #10
0
ファイル: platform_winrt.cpp プロジェクト: CaF2/hw
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
{
	SYSTEMTIME st_utc;
	SYSTEMTIME st_localtz;
	TIME_ZONE_INFORMATION tzi;
	DWORD tzid;
	PHYSFS_sint64 retval;
	struct tm tm;
	BOOL rc;

	BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), errcodeFromWinApi(), -1);
	tzid = GetTimeZoneInformation(&tzi);
	BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, errcodeFromWinApi(), -1);
	rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
	BAIL_IF_MACRO(!rc, errcodeFromWinApi(), -1);

	/* Convert to a format that mktime() can grok... */
	tm.tm_sec = st_localtz.wSecond;
	tm.tm_min = st_localtz.wMinute;
	tm.tm_hour = st_localtz.wHour;
	tm.tm_mday = st_localtz.wDay;
	tm.tm_mon = st_localtz.wMonth - 1;
	tm.tm_year = st_localtz.wYear - 1900;
	tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
	tm.tm_yday = -1;
	tm.tm_isdst = -1;

	/* Convert to a format PhysicsFS can grok... */
	retval = (PHYSFS_sint64)mktime(&tm);
	BAIL_IF_MACRO(retval == -1, PHYSFS_ERR_OS_ERROR, -1);
	return retval;
} /* FileTimeToPhysfsTime */
コード例 #11
0
PPH_STRING VirusTotalStringToTime(
    _In_ PPH_STRING Time
    )
{
    PPH_STRING result = NULL;
    SYSTEMTIME time = { 0 };
    SYSTEMTIME localTime = { 0 };

    swscanf(
        PhGetString(Time),
        L"%hu-%hu-%hu %hu:%hu:%hu",
        &time.wYear,
        &time.wMonth,
        &time.wDay,
        &time.wHour,
        &time.wMinute,
        &time.wSecond
        );

    if (SystemTimeToTzSpecificLocalTime(NULL, &time, &localTime))
    {
        result = PhFormatDateTime(&localTime);
    }

    return result;
}
コード例 #12
0
ファイル: System.cpp プロジェクト: Shikifuyin/Scarab-Engine
TimeValue System::UTCToLocalTime( TimeValue iUTCTime, TimeUnit iResolution, const TimeZone * pTimeZone ) const
{
    FILETIME hFlatTimeUTC;
    _RevertTimeValue( &hFlatTimeUTC, iUTCTime, iResolution );

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

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

        SYSTEMTIME hSystemTimeUTC;
        BOOL bRes = FileTimeToSystemTime( &hFlatTimeUTC, &hSystemTimeUTC );
        DebugAssert( bRes != FALSE );

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

        FILETIME hFlatTimeLocal;
        bRes = SystemTimeToFileTime( &hSystemTimeLocal, &hFlatTimeLocal );
        DebugAssert( bRes != FALSE );

        return _ConvertTimeValue( &hFlatTimeLocal, iResolution );
    }
}
コード例 #13
0
ファイル: time.c プロジェクト: ycsoft/pgbouncer
struct tm *localtime_r(const time_t *tp, struct tm *dst)
{
    ULARGE_INTEGER utc;
    FILETIME ft_utc;
    SYSTEMTIME st_utc, st_local;

    /* convert time_t to FILETIME */
    utc.QuadPart = (*tp + UNIX_EPOCH) * FT_SEC;
    ft_utc.dwLowDateTime = utc.LowPart;
    ft_utc.dwHighDateTime = utc.HighPart;

    /* split to parts and get local time */
    if (!FileTimeToSystemTime(&ft_utc, &st_utc))
        return NULL;
    if (!SystemTimeToTzSpecificLocalTime(NULL, &st_utc, &st_local))
        return NULL;

    /* fill struct tm */
    dst->tm_sec = st_local.wSecond;
    dst->tm_min = st_local.wMinute;
    dst->tm_hour = st_local.wHour;
    dst->tm_mday = st_local.wDay;
    dst->tm_mon = st_local.wMonth - 1;
    dst->tm_year = st_local.wYear - 1900;
    dst->tm_wday = st_local.wDayOfWeek;
    dst->tm_yday = 0;
    dst->tm_isdst = -1;
    return dst;
}
コード例 #14
0
ファイル: CrashInfoReader.cpp プロジェクト: doo/CrashRpt
BOOL CCrashInfoReader::IsRemindNowOK()
{
    if(GetRemindPolicy()!=REMIND_LATER)
        return FALSE; // User doesn want us to remind him

    // Get last remind date
    SYSTEMTIME LastRemind;
    if(!GetLastRemindDate(LastRemind))
    {   
		// We never reminded user - its time to remind now!
        return TRUE;
    }

    // Determine the period of time elapsed since the last remind.
    SYSTEMTIME CurTimeUTC, CurTimeLocal;
    GetSystemTime(&CurTimeUTC);
    SystemTimeToTzSpecificLocalTime(NULL, &CurTimeUTC, &CurTimeLocal);
    ULONG64 uCurTime = Utility::SystemTimeToULONG64(CurTimeLocal);
    ULONG64 uLastRemindTime = Utility::SystemTimeToULONG64(LastRemind);

    // Check that at lease one week elapsed
    double dDiffTime = (double)(uCurTime-uLastRemindTime)*10E-08;
    if(dDiffTime<7*24*60*60)
    {
		// Now, wait more time
        return FALSE;
    }

	// Remind now
    return TRUE;
}
コード例 #15
0
ファイル: display.c プロジェクト: RareHare/reactos
BOOL
GetFileModifyTime(LPCWSTR pFullPath, WCHAR * szTime, int szTimeSize)
{
    HANDLE hFile;
    FILETIME AccessTime;
    SYSTEMTIME SysTime, LocalTime;
    UINT Length;
    TIME_ZONE_INFORMATION TimeInfo;

    hFile = CreateFileW(pFullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    if (!hFile)
        return FALSE;

    if (!GetFileTime(hFile, NULL, NULL, &AccessTime))
    {
        CloseHandle(hFile);
        return FALSE;
    }
    CloseHandle(hFile);

    if(!GetTimeZoneInformation(&TimeInfo))
        return FALSE;

    if (!FileTimeToSystemTime(&AccessTime, &SysTime))
        return FALSE;

    if (!SystemTimeToTzSpecificLocalTime(&TimeInfo, &SysTime, &LocalTime))
        return FALSE;

    Length = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &LocalTime, NULL, szTime, szTimeSize);
    szTime[Length-1] = L' ';
    return GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT, &LocalTime, NULL, &szTime[Length], szTimeSize-Length);
}
コード例 #16
0
ファイル: BufferTimeList.cpp プロジェクト: triaxia/NppSalt
void BufferTimeList::ToLocalTime(FILETIME fileTime, TCHAR *localTime)
{
    SYSTEMTIME stUTC, stLocal;
    FileTimeToSystemTime(&fileTime, &stUTC);
    SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
    generic_sprintf(localTime, TEXT("at %02d:%02d:%02d on %02d/%02d/%d"), 
        stLocal.wHour, stLocal.wMinute, stLocal.wSecond, stLocal.wDay, stLocal.wMonth, stLocal.wYear);
}
コード例 #17
0
ファイル: FileUtils.cpp プロジェクト: amecky/diesel2D
	// -------------------------------------------------------
	// Checks if the file has changed
	// -------------------------------------------------------
	void logFileTime(const char* fileName) {
		FILETIME now;
		getFileTime(fileName,now);
		SYSTEMTIME stUTC, stLocal;
		FileTimeToSystemTime(&now, &stUTC);
		SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
		LOG << "file: " << fileName << " now: " << stLocal.wDay << "." << stLocal.wMonth << "." << stLocal.wYear << " " << stLocal.wHour << ":"<< stLocal.wMinute;		
	}
コード例 #18
0
ファイル: utils.cpp プロジェクト: ybznek/miranda-ng
void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst)
{
	FILETIME ft;
	SYSTEMTIME st;
	UnixTimeToFileTime(t, &ft);
	FileTimeToSystemTime(&ft, &st);
	SystemTimeToTzSpecificLocalTime(NULL, &st, pst);
}
コード例 #19
0
std::string FiletimeAsString( const FILETIME &ft )
{
	SYSTEMTIME stUTC, st;
	FILETIME localFt;
	FileTimeToSystemTime (&ft, &stUTC);
	SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &st);
	SystemTimeToFileTime(&st, &localFt);
	return  boost::posix_time::to_simple_string(boost::posix_time::from_ftime<boost::posix_time::ptime>(localFt));
}
コード例 #20
0
ファイル: GitRev.cpp プロジェクト: hfeeki/TortoiseGit
CTime GitRev::ConverFromString(CString input)
{
	// pick up date from string
	try
	{
		COleDateTime tm(_wtoi(input.Mid(0,4)),
				 _wtoi(input.Mid(5,2)),
				 _wtoi(input.Mid(8,2)),
				 _wtoi(input.Mid(11,2)),
				 _wtoi(input.Mid(14,2)),
				 _wtoi(input.Mid(17,2)));
		if( tm.GetStatus() != COleDateTime::valid )
			return CTime();//Error parsing time-string

		// pick up utc offset
		CString sign = input.Mid(20,1);		// + or -
		int hoursOffset =  _wtoi(input.Mid(21,2));
		int minsOffset = _wtoi(input.Mid(23,2));
		// convert to a fraction of a day
		double offset = (hoursOffset*60 + minsOffset) / 1440.0; // 1440 mins = 1 day
		if ( sign == "-" )
		{
			offset = -offset;
		}
		// we have to subtract this from the time given to get UTC
		tm -= offset;
		// get utc time as a SYSTEMTIME
		SYSTEMTIME sysTime;
		tm.GetAsSystemTime( sysTime );
		// and convert to users local time
		SYSTEMTIME local;
		if ( SystemTimeToTzSpecificLocalTime( &m_TimeZone, &sysTime, &local ) )
		{
			sysTime = local;
		}
		else
		{
			ASSERT(false);	// this should not happen but leave time in utc if it does
		}
		// convert to CTime and return
		return CTime( sysTime, -1 );
	}
	catch(CException* e)
	{
		//Probably the date was something like 1970-01-01 00:00:00. _mktime64() doesnt like this.
		//Dont let the application crash on this exception

#ifdef _AFX //CException classes are only defined when afx.h is included.
			//When afx.h is not included, the exception is leaked.
			//This will probably never happen because when CException is not defined, it cannot be thrown.
		e->Delete();
#else
		UNREFERENCED_PARAMETER(e);
#endif //ifdef _AFX
	}
	return CTime(); //Return an invalid time
}
コード例 #21
0
ファイル: pkcs11h-crypto.c プロジェクト: Kjuly/Tunnelblick
static
int
__pkcs11h_crypto_win32_certificate_get_expiration (
	IN void * const global_data,
	IN const unsigned char * const blob,
	IN const size_t blob_size,
	OUT time_t * const expiration
) {
	__crypto_win32_data_t data = (__crypto_win32_data_t)global_data;
	PCCERT_CONTEXT cert = NULL;
	PKCS11H_BOOL ok = FALSE;
	SYSTEMTIME ust, st;
	struct tm tm1;

	_PKCS11H_ASSERT (global_data!=NULL);
	_PKCS11H_ASSERT (blob!=NULL);
	_PKCS11H_ASSERT (expiration!=NULL);

	*expiration = (time_t)0;

	if (
		(cert = data->p_CertCreateCertificateContext (
			PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
			blob,
			blob_size
		)) == NULL ||
		!FileTimeToSystemTime (
			&cert->pCertInfo->NotAfter,
			&ust
		)
	) {
		goto cleanup;
	}

	SystemTimeToTzSpecificLocalTime (NULL, &ust, &st);
	memset (&tm1, 0, sizeof (tm1));
	tm1.tm_year = st.wYear - 1900;
	tm1.tm_mon  = st.wMonth - 1;
	tm1.tm_mday = st.wDay;
	tm1.tm_hour = st.wHour;
	tm1.tm_min  = st.wMinute;
	tm1.tm_sec  = st.wSecond;

	*expiration = mktime (&tm1);

	ok = TRUE;

cleanup:

	if (cert != NULL) {
		data->p_CertFreeCertificateContext (cert);
		cert = NULL;
	}

	return ok != FALSE;
}
コード例 #22
0
static inline QDateTime fileTimeToQDateTime(const FILETIME *time)
{
    QDateTime ret;
    SYSTEMTIME sTime, lTime;
    FileTimeToSystemTime(time, &sTime);
    SystemTimeToTzSpecificLocalTime(0, &sTime, &lTime);
    ret.setDate(QDate(lTime.wYear, lTime.wMonth, lTime.wDay));
    ret.setTime(QTime(lTime.wHour, lTime.wMinute, lTime.wSecond, lTime.wMilliseconds));
    return ret;
}
コード例 #23
0
ファイル: winrt.cpp プロジェクト: ahrnbom/physfs-uwp
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
{
	SYSTEMTIME st_utc;
	SYSTEMTIME st_localtz;
	TIME_ZONE_INFORMATION tzi;
	DWORD tzid;
	PHYSFS_sint64 retval;
	struct tm tm;

	BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), winApiStrError(), -1);
	tzid = GetTimeZoneInformation(&tzi);
	BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, winApiStrError(), -1);

	/* (This API is unsupported and fails on non-NT systems. */
	if (!SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz))
	{
		/* do it by hand. Grumble... */
		ULARGE_INTEGER ui64;
		FILETIME new_ft;
		ui64.LowPart = ft->dwLowDateTime;
		ui64.HighPart = ft->dwHighDateTime;

		if (tzid == TIME_ZONE_ID_STANDARD)
			tzi.Bias += tzi.StandardBias;
		else if (tzid == TIME_ZONE_ID_DAYLIGHT)
			tzi.Bias += tzi.DaylightBias;

		/* convert from minutes to 100-nanosecond increments... */
		ui64.QuadPart -= (((LONGLONG)tzi.Bias) * (600000000));

		/* Move it back into a FILETIME structure... */
		new_ft.dwLowDateTime = ui64.LowPart;
		new_ft.dwHighDateTime = ui64.HighPart;

		/* Convert to something human-readable... */
		if (!FileTimeToSystemTime(&new_ft, &st_localtz))
			BAIL_MACRO(winApiStrError(), -1);
	} /* if */

	  /* Convert to a format that mktime() can grok... */
	tm.tm_sec = st_localtz.wSecond;
	tm.tm_min = st_localtz.wMinute;
	tm.tm_hour = st_localtz.wHour;
	tm.tm_mday = st_localtz.wDay;
	tm.tm_mon = st_localtz.wMonth - 1;
	tm.tm_year = st_localtz.wYear - 1900;
	tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
	tm.tm_yday = -1;
	tm.tm_isdst = -1;

	/* Convert to a format PhysicsFS can grok... */
	retval = (PHYSFS_sint64)mktime(&tm);
	BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
	return(retval);
} /* FileTimeToPhysfsTime */
コード例 #24
0
BOOL My_SystemTimeToTzSpecificLocalTime()
{
	LPTIME_ZONE_INFORMATION lpTimeZoneInformation=NULL;
	LPSYSTEMTIME lpUniversalTime=NULL;
	LPSYSTEMTIME lpLocalTime=NULL;
	BOOL returnVal_Real = NULL;
	BOOL returnVal_Intercepted = NULL;

	DWORD error_Real = 0;
	DWORD error_Intercepted = 0;
	__try{
	disableInterception();
	returnVal_Real = SystemTimeToTzSpecificLocalTime (lpTimeZoneInformation,lpUniversalTime,lpLocalTime);
	error_Real = GetLastError();
	enableInterception();
	returnVal_Intercepted = SystemTimeToTzSpecificLocalTime (lpTimeZoneInformation,lpUniversalTime,lpLocalTime);
	error_Intercepted = GetLastError();
	}__except(puts("in filter"), 1){puts("exception caught");}
	return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
コード例 #25
0
CString CUserFile::GetModifyTime(CString appname)
{   
	WIN32_FIND_DATA ffd ;   
	HANDLE hFind = FindFirstFile(appname,&ffd);   
	SYSTEMTIME stUTC, stLocal;   
	FileTimeToSystemTime(&(ffd.ftLastWriteTime), &stUTC);   
	SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);   
	CString strTmp = "";   
	strTmp.Format("%d-%d-%d,%d:%d", stLocal.wYear,stLocal.wMonth,stLocal.wDay,stLocal.wHour,stLocal.wMinute);   
	return strTmp;   
}
コード例 #26
0
ファイル: filesys.cpp プロジェクト: jadesoul/libsoul
	const list<ushort> path::ftime2list(FILETIME& ftime) {
		TIME_ZONE_INFORMATION zoneinfo;
		GetTimeZoneInformation(&zoneinfo);
		SYSTEMTIME greenwichsystime, localtime;
		FileTimeToSystemTime(&ftime, &greenwichsystime);
		SystemTimeToTzSpecificLocalTime(&zoneinfo, &greenwichsystime, &localtime);
		ushort& year=localtime.wYear, &month=localtime.wMonth, &day=localtime.wDay, 
			&hour=localtime.wHour, &min=localtime.wMinute, &sec=localtime.wSecond,
			&msec=localtime.wMilliseconds;
		return list<ushort>(year, month, day, hour, min, sec, msec);
	}
コード例 #27
0
ファイル: TimeUtil.cpp プロジェクト: HTshandou/TouchMind
bool touchmind::util::TimeUtil::SystemTimeToLocalSystemTime(SYSTEMTIME systemTime, SYSTEMTIME* localSystemTime)
{
    TIME_ZONE_INFORMATION timeZoneInfo;
    if (GetTimeZoneInformation(&timeZoneInfo) == TIME_ZONE_ID_INVALID) {
        return false;
    }

    if (SystemTimeToTzSpecificLocalTime(&timeZoneInfo, &systemTime, localSystemTime) == 0) {
        return false;
    }
    return true;
}
コード例 #28
0
ファイル: main.cpp プロジェクト: henrypp/timevertor
void _app_gettime (time_t unixtime, LONG bias, LPSYSTEMTIME lpst)
{
	SYSTEMTIME st = {0};
	_r_unixtime_to_systemtime (unixtime, &st);

	current_timestamp_utc = unixtime; // store position of current time (utc)

	TIME_ZONE_INFORMATION tz = {0};
	tz.Bias = bias; // set timezone shift

	SystemTimeToTzSpecificLocalTime (&tz, &st, lpst);
}
コード例 #29
0
// ---------------------------------------------
// Append the text to the logging window
// ---------------------------------------------
VOID CGreenPrintWindowLogging::Log( LPWSTR Text )
{
	DWORD ErrorCode = GetLastError();

	if ( NULL != Text && NULL != m_hWndEdit )
	{
		SYSTEMTIME CurrentTimeUTC;
		GetSystemTime( &CurrentTimeUTC );

		SYSTEMTIME CurrentTimeLocal;
		SystemTimeToTzSpecificLocalTime( NULL, &CurrentTimeUTC, &CurrentTimeLocal );

		WCHAR TimeText[ 128 ] = { 0 };
		StringCchPrintf( TimeText, _countof(TimeText), L"%02d/%02d/%d  %02d:%02d:%02d: ",
			CurrentTimeLocal.wMonth, CurrentTimeLocal.wDay, CurrentTimeLocal.wYear,
			CurrentTimeLocal.wHour, CurrentTimeLocal.wMinute, CurrentTimeLocal.wSecond );
		
		WCHAR ErrorText[ 64 ] = { 0 };
		if ( NO_ERROR != ErrorCode )
		{
			StringCchPrintf( ErrorText, _countof(ErrorText), L" (%d)", ErrorCode );
		}

		WCHAR *NewLine = L"\r\n";

		DWORD cchNewText = GetWindowTextLength( m_hWndEdit ) + wcslen(TimeText) + wcslen(Text) + wcslen(ErrorText) + wcslen(NewLine) + 1;

		WCHAR *NewText = (WCHAR*)LocalAlloc( LMEM_ZEROINIT, cchNewText * sizeof(WCHAR) );

		if ( NULL != NewText )
		{
			GetWindowText( m_hWndEdit, NewText, cchNewText );

			if ( SUCCEEDED( StringCchCat( NewText, cchNewText, TimeText ) ) )
			{
				if ( SUCCEEDED( StringCchCat( NewText, cchNewText, Text ) ) )
				{
					if ( SUCCEEDED( StringCchCat( NewText, cchNewText, ErrorText ) ) )
					{
						if ( SUCCEEDED( StringCchCat( NewText, cchNewText, NewLine ) ) )
						{
							SetWindowText( m_hWndEdit, NewText );
						}
					}
				}
			}

			LocalFree( NewText );
			NewText = NULL;
		}
	}
}
コード例 #30
0
	static Time::DateTime datetime_for_filetime(FILETIME filetime) {
		Time::DateTime dt;

		SYSTEMTIME systime, localtime;
		FileTimeToSystemTime(&filetime, &systime);
		SystemTimeToTzSpecificLocalTime(0, &systime, &localtime);

		dt = Time::DateTime(
			localtime.wYear, localtime.wMonth, localtime.wDay,
			localtime.wHour, localtime.wMinute, localtime.wSecond);
		dt += Time::TimeDelta(localtime.wMilliseconds, Time::Millisecond);
		return dt;
	}