Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarTime_windows.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/core/StarTime_windows.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/core/StarTime_windows.cpp')
-rw-r--r--source/core/StarTime_windows.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/source/core/StarTime_windows.cpp b/source/core/StarTime_windows.cpp
new file mode 100644
index 0000000..2b3e797
--- /dev/null
+++ b/source/core/StarTime_windows.cpp
@@ -0,0 +1,68 @@
+#include "StarTime.hpp"
+#include "StarLexicalCast.hpp"
+#include "StarMathCommon.hpp"
+
+#include <ctime>
+#include <windows.h>
+
+namespace Star {
+
+String Time::printDateAndTime(int64_t epochTicks, String format) {
+ // playing fast and loose with the standard here...
+ time_t requestedTime = epochTicks / epochTickFrequency();
+ struct tm* ptm;
+ ptm = localtime(&requestedTime);
+
+ return format.replaceTags(StringMap<String>{
+ {"year", strf("%04d", ptm->tm_year + 1900)},
+ {"month", strf("%02d", ptm->tm_mon + 1)},
+ {"day", strf("%02d", ptm->tm_mday)},
+ {"hours", strf("%02d", ptm->tm_hour)},
+ {"minutes", strf("%02d", ptm->tm_min)},
+ {"seconds", strf("%02d", ptm->tm_sec)},
+ {"millis", strf("%03d", (epochTicks % epochTickFrequency()) / (epochTickFrequency() / 1000))},
+ });
+}
+
+int64_t Time::epochTicks() {
+ FILETIME ft_now;
+ GetSystemTimeAsFileTime(&ft_now);
+ LONGLONG now = (LONGLONG)ft_now.dwLowDateTime + ((LONGLONG)(ft_now.dwHighDateTime) << 32LL);
+ now -= 116444736000000000LL;
+ return now;
+}
+
+int64_t Time::epochTickFrequency() {
+ return 10000000LL;
+}
+
+struct MonotonicClock {
+ MonotonicClock() {
+ QueryPerformanceFrequency(&freq);
+ };
+
+ int64_t ticks() const {
+ LARGE_INTEGER ticks;
+ QueryPerformanceCounter(&ticks);
+ return ticks.QuadPart;
+ }
+
+ int64_t frequency() const {
+ return freq.QuadPart;
+ }
+
+ LARGE_INTEGER freq;
+};
+
+static MonotonicClock g_monotonicClock;
+
+int64_t Time::monotonicTicks() {
+ return g_monotonicClock.ticks();
+}
+
+int64_t Time::monotonicTickFrequency() {
+ return g_monotonicClock.frequency();
+}
+
+
+}