6 releases (breaking)

0.27.0 Oct 30, 2024
0.26.0 Sep 9, 2024
0.25.0 Aug 20, 2024
0.24.1 Aug 13, 2024
0.23.0 Jun 17, 2024

#18 in #system-clock

Download history 1467/week @ 2024-07-30 1485/week @ 2024-08-06 1655/week @ 2024-08-13 1225/week @ 2024-08-20 1283/week @ 2024-08-27 1956/week @ 2024-09-03 1769/week @ 2024-09-10 914/week @ 2024-09-17 1151/week @ 2024-09-24 989/week @ 2024-10-01 1232/week @ 2024-10-08 1712/week @ 2024-10-15 939/week @ 2024-10-22 1129/week @ 2024-10-29 1159/week @ 2024-11-05 1959/week @ 2024-11-12

5,341 downloads per month
Used in 26 crates (6 directly)

MIT/Apache

20KB
361 lines

Time module provides a non-global clock, which should be passed as an argument to functions which need to read the current time. In particular try to avoid storing the clock instances in the objects. Functions which use system clock directly are non-hermetic, which makes them effectively non-deterministic and hard to test.

Clock provides 2 types of time reads:

  1. now() (aka POSIX CLOCK_MONOTONIC, aka time::Instant) time as perceived by the machine making the measurement. The subsequent calls to now() are guaranteed to return monotonic results. It should be used for measuring the latency of operations as observed by the machine. The time::Instant itself doesn't translate to any specific timestamp, so it is not meaningful for anyone other than the machine doing the measurement.
  2. now_utc() (aka POSIX CLOCK_REALTIME, aka time::Utc) expected to approximate the (global) UTC time. There is NO guarantee that the subsequent reads will be monotonic, as CLOCK_REALTIME it configurable in the OS settings, or can be updated during NTP sync. Should be used whenever you need to communicate a timestamp over the network, or store it for later use. Remember that clocks of different machines are not perfectly synchronized, and in extreme cases can be totally skewed.

Dependencies

~1–7.5MB
~53K SLoC