From 90a89e0055b6bfb91f1c63d8194bd966a1068b9c Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Mon, 28 Jun 2021 15:13:24 -0500 Subject: [PATCH] Use monotonically-increasing time stamps. Fixes #150 --- src/timestamp_unix.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/timestamp_unix.cpp b/src/timestamp_unix.cpp index 28f0ac86..ab4efdec 100644 --- a/src/timestamp_unix.cpp +++ b/src/timestamp_unix.cpp @@ -5,9 +5,9 @@ #include "timeconv.h" void get_current_time(timespec *ts) { - timeval tv; - gettimeofday(&tv, NULL); - *ts = timevalToTimespec(tv); + // CLOCK_MONOTONIC ensures that we never get timestamps that go backward in + // time due to clock adjustment. https://github.com/r-lib/later/issues/150 + clock_gettime(CLOCK_MONOTONIC, ts); } class TimestampImplPosix : public TimestampImpl {