4 releases (2 breaking)

0.25.0 Aug 20, 2024
0.24.1 Aug 13, 2024
0.24.0 Aug 5, 2024
0.23.0 Jun 17, 2024

#15 in #system-clock

Download history 268/week @ 2024-06-14 272/week @ 2024-06-21 252/week @ 2024-06-28 592/week @ 2024-07-05 504/week @ 2024-07-12 708/week @ 2024-07-19 1128/week @ 2024-07-26 1444/week @ 2024-08-02 1743/week @ 2024-08-09 1419/week @ 2024-08-16 1056/week @ 2024-08-23 1125/week @ 2024-08-30

5,666 downloads per month
Used in 24 crates (6 directly)

MIT/Apache

19KB
360 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

~0.7–2MB
~37K SLoC