#timestamp #clock #source #system #monotonic #suspend #serialization

zeitstempel

A timestamp you can serialize, and it might include suspend time

3 unstable releases

0.1.1 Mar 18, 2021
0.1.0 Mar 10, 2021
0.0.0 Mar 3, 2021

#266 in Operating systems

Download history 1988/week @ 2023-12-14 906/week @ 2023-12-21 1135/week @ 2023-12-28 1596/week @ 2024-01-04 1614/week @ 2024-01-11 2976/week @ 2024-01-18 2192/week @ 2024-01-25 2223/week @ 2024-02-01 2961/week @ 2024-02-08 1345/week @ 2024-02-15 1530/week @ 2024-02-22 1479/week @ 2024-02-29 1479/week @ 2024-03-07 2096/week @ 2024-03-14 2072/week @ 2024-03-21 1125/week @ 2024-03-28

7,071 downloads per month
Used in 3 crates (via glean-core)

MPL-2.0 license

12KB
77 lines

zeitstempel

Crates.io version docs.rs docs License: MPL 2.0 Build Status

zeitstempel is German for "timestamp".


Time's hard. Correct time is near impossible.

This crate has one purpose: give me a timestamp as an integer, coming from a monotonic clock source, include time across suspend/hibernation of the host machine and let me compare it to other timestamps.

It becomes the developer's responsibility to only compare timestamps obtained from this clock source. Timestamps are not comparable across operating system reboots.

Why not std::time::Instant?

std::time::Instant fulfills some of our requirements:

  • It's monotonic, guaranteed (sort of).
  • It can be compared to other timespans.

However:

  • It can't be serialized.
  • It's not guaranteed that the clock source it uses contains suspend/hibernation time across all operating systems.

Example

use std::{thread, time::Duration};

let start = zeitstempel::now();
thread::sleep(Duration::from_millis(2));

let diff = Duration::from_nanos(zeitstempel::now() - start);
assert!(diff >= Duration::from_millis(2));

Supported operating systems

We support the following operating systems:

  • Windows*
  • macOS
  • Linux
  • Android
  • iOS

For other operating systems there's a fallback to std::time::Instant, compared against a process-global fixed reference point. We don't guarantee that measured time includes time the system spends in sleep or hibernation.

* To use native Windows 10 functionality enable the win10plus feature. Otherwise it will use the fallback.

License

MPL 2.0. See LICENSE.

Dependencies

~63KB