[flang] [llvm] [flang-rt] Add implementation for date_and_time on Windows (PR #190174)

David Truby via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 08:33:23 PDT 2026


================
@@ -399,6 +410,41 @@ template <typename TM = struct tm> struct GmtOffsetHelper {
   };
 };
 
+#ifdef _WIN32
+struct timeval {
+  std::int64_t tv_sec;
+  std::int64_t tv_usec;
+};
+
+// gettimeofday half-implementation for win32; ignore the timezone as we don't
+// use it anyway
+int gettimeofday(timeval *tv, void *) {
+  constexpr std::uint64_t epoch_offset{116444736000000000ull};
+
+  FILETIME ftime;
+  GetSystemTimePreciseAsFileTime(&ftime);
+
+  // Convert ftime to a real 64-bit integer
+  std::uint64_t time{
+      ULARGE_INTEGER{{ftime.dwLowDateTime, ftime.dwHighDateTime}}.QuadPart};
+  // Convert to Unix epoch time
+  time -= epoch_offset;
+
+  auto [sec, usec] = std::lldiv(time, 10000000L);
----------------
DavidTruby wrote:

I've added digit separators to make it clearer, as I agree that it's pretty hard to read 

https://github.com/llvm/llvm-project/pull/190174


More information about the llvm-commits mailing list