Skip to content

Commit

Permalink
fix #33 monotonic_now() to be OS agnostic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WadeGulbrandsen authored Dec 12, 2024
1 parent 7736c64 commit c533716
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/birl_ffi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c533716

Please sign in to comment.