new_build_system (#18)
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
Reviewed-on: #18
This commit is contained in:
@ -22,32 +22,6 @@
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory::utils::time {
|
||||
#if defined(_WIN32)
|
||||
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
|
||||
auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t {
|
||||
LARGE_INTEGER date{};
|
||||
date.HighPart = static_cast<LONG>(file_time.dwHighDateTime);
|
||||
date.LowPart = file_time.dwLowDateTime;
|
||||
date.QuadPart -= 116444736000000000LL;
|
||||
|
||||
return static_cast<std::uint64_t>(date.QuadPart) * 100ULL;
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto get_file_time_now() -> std::uint64_t {
|
||||
#if defined(_WIN32)
|
||||
SYSTEMTIME sys_time{};
|
||||
::GetSystemTime(&sys_time);
|
||||
|
||||
FILETIME file_time{};
|
||||
::SystemTimeToFileTime(&sys_time, &file_time);
|
||||
return static_cast<std::uint64_t>(
|
||||
(reinterpret_cast<LARGE_INTEGER *>(&file_time))->QuadPart);
|
||||
#else // !defined(_WIN32)
|
||||
return get_time_now();
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
void get_local_time_now(struct tm &local_time) {
|
||||
std::memset(&local_time, 0, sizeof(local_time));
|
||||
|
||||
@ -61,21 +35,10 @@ void get_local_time_now(struct tm &local_time) {
|
||||
}
|
||||
|
||||
auto get_time_now() -> std::uint64_t {
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
#if defined(__APPLE__)
|
||||
return std::chrono::nanoseconds(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
#else // !defined(__APPLE__)
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::nanoseconds(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch())
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
#endif // defined(__APPLE__)
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
@ -91,17 +54,35 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char * {
|
||||
return reinterpret_cast<const char *>(s + input.tellg());
|
||||
}
|
||||
|
||||
auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t {
|
||||
return static_cast<std::uint64_t>(time * NANOS_PER_SECOND);
|
||||
}
|
||||
|
||||
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
|
||||
auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
|
||||
const auto win_time = (unix_time / 100ULL) + 116444736000000000ULL;
|
||||
auto win_time = unix_time_to_windows_time(unix_time);
|
||||
|
||||
FILETIME file_time{};
|
||||
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
|
||||
file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
|
||||
return file_time;
|
||||
}
|
||||
|
||||
auto windows_file_time_to_unix_time(FILETIME win_time) -> std::uint64_t {
|
||||
return windows_time_to_unix_time(
|
||||
(static_cast<std::uint64_t>(win_time.dwHighDateTime) << 32ULL) |
|
||||
static_cast<std::uint64_t>(win_time.dwLowDateTime));
|
||||
}
|
||||
|
||||
auto windows_time_t_to_unix_time(__time64_t win_time) -> std::uint64_t {
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::system_clock::from_time_t(win_time).time_since_epoch())
|
||||
.count());
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t {
|
||||
return (unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
|
||||
}
|
||||
|
||||
auto windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t {
|
||||
return (win_time * WIN32_TIME_NANOS_PER_TICK) - WIN32_TIME_CONVERSION;
|
||||
}
|
||||
} // namespace repertory::utils::time
|
||||
|
Reference in New Issue
Block a user