updated build system

This commit is contained in:
2024-08-23 12:01:46 -05:00
parent 52f2b5b118
commit d4f0431cd5
8 changed files with 71 additions and 40 deletions

View File

@ -25,7 +25,9 @@
#include "utils/config.hpp"
namespace repertory::utils::time {
inline constexpr const auto NANOS_PER_SECOND = 1000000000L;
inline constexpr const auto NANOS_PER_SECOND = 1000000000ULL;
inline constexpr const auto WIN32_TIME_CONVERSION{116444736000000000ULL};
inline constexpr const auto WIN32_TIME_NANOS_PER_TICK{100ULL};
#if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT)
[[nodiscard]] inline auto convert_to_utc(time_t time) -> std::time_t {
@ -57,6 +59,12 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char *;
[[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME;
#endif // defined(_WIN32)
[[nodiscard]] auto
unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t;
[[nodiscard]] auto
windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t;
} // namespace repertory::utils::time
#endif // REPERTORY_INCLUDE_UTILS_TIME_HPP_

View File

@ -28,9 +28,9 @@ 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;
date.QuadPart -= WIN32_TIME_CONVERSION;
return static_cast<std::uint64_t>(date.QuadPart) * 100ULL;
return static_cast<std::uint64_t>(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK;
}
#endif // defined(_WIN32)
@ -47,11 +47,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>(_time64(nullptr));
#else // !defined(_WIN32)
return static_cast<std::uint64_t>(time(nullptr));
#endif // defined(_WIN32)
return static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
#if defined(_WIN32)
@ -73,11 +72,20 @@ auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t {
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
auto win_time = (unix_time / 100ULL) + 116444736000000000ULL;
auto win_time =
(unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
FILETIME file_time{};
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
return file_time;
}
#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_CONVERSION) * WIN32_TIME_NANOS_PER_TICK;
}
} // namespace repertory::utils::time