/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Platform/Win/Timestamp_Win.cpp
81 строка
2 KB
Ingrater
Clang-format fixes and update to 18.1.1 (#1234)
10 мар 2024, 15:51
Не верифицирован
10 мар 2024, 15:51
2f16acf
Код
Авторство
О чём код?
#include <Foundation/FoundationPCH.h> #if EZ_ENABLED(EZ_PLATFORM_WINDOWS) # include <Foundation/Time/Timestamp.h> // Helper function to shift windows file time into Unix epoch (in microseconds). ezInt64 FileTimeToEpoch(FILETIME fileTime) { ULARGE_INTEGER currentTime; currentTime.LowPart = fileTime.dwLowDateTime; currentTime.HighPart = fileTime.dwHighDateTime; ezInt64 iTemp = currentTime.QuadPart / 10; iTemp -= 11644473600000000LL; return iTemp; } // Helper function to shift Unix epoch (in microseconds) into windows file time. FILETIME EpochToFileTime(ezInt64 iFileTime) { ezInt64 iTemp = iFileTime + 11644473600000000LL; iTemp *= 10; FILETIME fileTime; ULARGE_INTEGER currentTime; currentTime.QuadPart = iTemp; fileTime.dwLowDateTime = currentTime.LowPart; fileTime.dwHighDateTime = currentTime.HighPart; return fileTime; } const ezTimestamp ezTimestamp::CurrentTimestamp() { FILETIME fileTime; GetSystemTimeAsFileTime(&fileTime); return ezTimestamp::MakeFromInt(FileTimeToEpoch(fileTime), ezSIUnitOfTime::Microsecond); } const ezTimestamp ezDateTime::GetTimestamp() const { SYSTEMTIME st; FILETIME fileTime; memset(&st, 0, sizeof(SYSTEMTIME)); st.wYear = (WORD)m_iYear; st.wMonth = m_uiMonth; st.wDay = m_uiDay; st.wDayOfWeek = m_uiDayOfWeek; st.wHour = m_uiHour; st.wMinute = m_uiMinute; st.wSecond = m_uiSecond; st.wMilliseconds = (WORD)(m_uiMicroseconds / 1000); BOOL res = SystemTimeToFileTime(&st, &fileTime); ezTimestamp timestamp; if (res != 0) timestamp = ezTimestamp::MakeFromInt(FileTimeToEpoch(fileTime), ezSIUnitOfTime::Microsecond); return timestamp; } ezResult ezDateTime::SetFromTimestamp(ezTimestamp timestamp) { FILETIME fileTime = EpochToFileTime(timestamp.GetInt64(ezSIUnitOfTime::Microsecond)); SYSTEMTIME st; BOOL res = FileTimeToSystemTime(&fileTime, &st); if (res == 0) return EZ_FAILURE; m_iYear = (ezInt16)st.wYear; m_uiMonth = (ezUInt8)st.wMonth; m_uiDay = (ezUInt8)st.wDay; m_uiDayOfWeek = (ezUInt8)st.wDayOfWeek; m_uiHour = (ezUInt8)st.wHour; m_uiMinute = (ezUInt8)st.wMinute; m_uiSecond = (ezUInt8)st.wSecond; m_uiMicroseconds = ezUInt32(st.wMilliseconds * 1000); return EZ_SUCCESS; } #endif