From 1976003e91170b53d3d22d506d862f46db162df5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 10 Aug 2021 14:15:53 +0200 Subject: time/FileTime: allow negative times --- src/time/FileTime.hxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/time/FileTime.hxx b/src/time/FileTime.hxx index 67fd5770b..a134433e3 100644 --- a/src/time/FileTime.hxx +++ b/src/time/FileTime.hxx @@ -47,10 +47,16 @@ ToUint64(FILETIME ft) noexcept return ConstructUint64(ft.dwLowDateTime, ft.dwHighDateTime); } +constexpr int_least64_t +ToInt64(FILETIME ft) noexcept +{ + return ToUint64(ft); +} + constexpr time_t FileTimeToTimeT(FILETIME ft) noexcept { - return (ToUint64(ft) - 116444736000000000) / 10000000; + return (ToInt64(ft) - 116444736000000000) / 10000000; } inline std::chrono::system_clock::time_point @@ -63,7 +69,7 @@ FileTimeToChrono(FILETIME ft) noexcept constexpr std::chrono::seconds DeltaFileTimeS(FILETIME a, FILETIME b) noexcept { - return std::chrono::seconds((ToUint64(a) - ToUint64(b)) / 10000000); + return std::chrono::seconds((ToInt64(a) - ToInt64(b)) / 10000000); } #endif -- cgit v1.2.3