From c937d3160dc5a3120756e3f2ccb07b775155cb83 Mon Sep 17 00:00:00 2001 From: Andrew Sasmito Date: Fri, 14 Aug 2026 16:27:15 -0400 Subject: [PATCH] Fix error with nanoseconds on windows Signed-off-by: Andrew Sasmito --- cpp/csp/core/Platform.h | 2 +- cpp/tests/core/test_time.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cpp/csp/core/Platform.h b/cpp/csp/core/Platform.h index 37474faf6..f0735ea20 100644 --- a/cpp/csp/core/Platform.h +++ b/cpp/csp/core/Platform.h @@ -47,7 +47,7 @@ inline tm * localtime_r( const time_t * timep, tm * result ) inline int nanosleep(const timespec* req, timespec* rem) { assert(rem == nullptr); - int64_t millis = req->tv_sec * 1000 + req->tv_nsec * 1000000; + int64_t millis = req->tv_sec * 1000 + req->tv_nsec / 1000000; Sleep(millis); return 0; } diff --git a/cpp/tests/core/test_time.cpp b/cpp/tests/core/test_time.cpp index a50bf15d9..1772e1f93 100644 --- a/cpp/tests/core/test_time.cpp +++ b/cpp/tests/core/test_time.cpp @@ -296,6 +296,18 @@ TEST( DateTest, test_basic_functionality ) } } +TEST( sleep, nanoseconds ) +{ + TimeDelta waittime = TimeDelta::fromNanoseconds( 100'000'000 ); // 100 ms + DateTime t1 = DateTime::now(); + + csp::sleep( waittime ); + + DateTime t2 = DateTime::now(); + + ASSERT_GE( t2 - t1, waittime ); +} + TEST( sleep, basic_functionality ) { TimeDelta waittime = TimeDelta::fromSeconds( 1 );