diff src/core/time.cc @ 308:da2c5a8ff306

time: don't use time_t!
author Paper <paper@paper.us.eu.org>
date Tue, 11 Jun 2024 04:24:19 -0400
parents f4538a4c91ba
children d928ec7b6a0d
line wrap: on
line diff
--- 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 <ctime>
 #include <string>
 
+#include <QDateTime>
+
 namespace Time {
 
-static int64_t GetSecondsInMinutes(Timestamp length) {
+static Timestamp GetSecondsInMinutes(Timestamp length) {
 	return std::llround(static_cast<double>(length) / 60.0);
 }
 
-static int64_t GetSecondsInHours(Timestamp length) {
+static Timestamp GetSecondsInHours(Timestamp length) {
 	return std::llround(static_cast<double>(length) / 3600.0);
 }
 
-static int64_t GetSecondsInDays(Timestamp length) {
+static Timestamp GetSecondsInDays(Timestamp length) {
 	return std::llround(static_cast<double>(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<int64_t>(t);
+Timestamp GetSystemTime() {
+	return QDateTime::currentDateTime().toUTC().toSecsSinceEpoch();
 }
 
 } // namespace Time