# HG changeset patch # User Paper # Date 1718094259 14400 # Node ID da2c5a8ff306eee6c0324b6cc463ba50c9e928a8 # Parent 8769c5d50b0627f029618264aa20e98137c5123a time: don't use time_t! diff -r 8769c5d50b06 -r da2c5a8ff306 include/core/time.h --- a/include/core/time.h Sun May 19 18:25:14 2024 -0400 +++ b/include/core/time.h Tue Jun 11 04:24:19 2024 -0400 @@ -6,7 +6,7 @@ namespace Time { /* this is in SECONDS */ -using Timestamp = uint64_t; +using Timestamp = int64_t; enum class Units { Seconds, @@ -16,7 +16,8 @@ std::string GetSecondsAsRelativeString(Timestamp length); std::string GetSecondsAsAbsoluteString(Units unit_cutoff, Timestamp amount, double unit_in_seconds = 1.0); -int64_t GetSystemTime(); +/* in UTC */ +Timestamp GetSystemTime(); }; // namespace Time diff -r 8769c5d50b06 -r da2c5a8ff306 src/core/time.cc --- a/src/core/time.cc Sun May 19 18:25:14 2024 -0400 +++ b/src/core/time.cc Tue Jun 11 04:24:19 2024 -0400 @@ -7,24 +7,26 @@ #include #include +#include + namespace Time { -static int64_t GetSecondsInMinutes(Timestamp length) { +static Timestamp GetSecondsInMinutes(Timestamp length) { return std::llround(static_cast(length) / 60.0); } -static int64_t GetSecondsInHours(Timestamp length) { +static Timestamp GetSecondsInHours(Timestamp length) { return std::llround(static_cast(length) / 3600.0); } -static int64_t GetSecondsInDays(Timestamp length) { +static Timestamp GetSecondsInDays(Timestamp length) { return std::llround(static_cast(length) / 86400.0); } std::string GetSecondsAsRelativeString(Timestamp length) { std::string result; - auto get = [](int64_t val, const std::string& s, const std::string& p) { + auto get = [](Timestamp val, const std::string& s, const std::string& p) { return Strings::ToUtf8String(val) + " " + (val == 1 ? s : p); }; @@ -92,10 +94,8 @@ return string.str(); } -int64_t GetSystemTime() { - static_assert(sizeof(int64_t) >= sizeof(time_t)); - time_t t = std::time(nullptr); - return static_cast(t); +Timestamp GetSystemTime() { + return QDateTime::currentDateTime().toUTC().toSecsSinceEpoch(); } } // namespace Time