From c533716c6fcbaf9b1ae0b12df50a2cea21080feb Mon Sep 17 00:00:00 2001 From: Wade Gulbrandsen <18219797+WadeGulbrandsen@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:33:28 -0500 Subject: [PATCH] fix #33 monotonic_now() to be OS agnostic Dividing by 1000 only works when the OS's native time is in nanoseconds. Using erlang:convert_time_unit/3 should work on all platforms. --- src/birl_ffi.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/birl_ffi.erl b/src/birl_ffi.erl index 8c8e16e..5792ab7 100644 --- a/src/birl_ffi.erl +++ b/src/birl_ffi.erl @@ -78,7 +78,8 @@ local_timezone() -> monotonic_now() -> StartTime = erlang:system_info(start_time), CurrentTime = erlang:monotonic_time(), - (CurrentTime - StartTime) div 1_000. + Difference = (CurrentTime - StartTime), + erlang:convert_time_unit(Difference, native, microsecond). to_parts(Timestamp, Offset) -> {Date, {Hour, Minute, Second}} = calendar:system_time_to_universal_time(