Debian Codegraph @

third_party/rust/zeitstempel/README.md

raw
1 # zeitstempel
2
3 [![Crates.io version](https://img.shields.io/crates/v/zeitstempel.svg?style=flat-square)](https://crates.io/crates/zeitstempel)
4 [![docs.rs docs](https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square)](https://docs.rs/zeitstempel)
5 [![License: MPL 2.0](https://img.shields.io/github/license/badboy/zeitstempel?style=flat-square)](LICENSE)
6 [![Build Status](https://img.shields.io/github/workflow/status/badboy/zeitstempel/CI?style=flat-square)](https://github.com/badboy/zeitstempel/actions?query=workflow%3ACI)
7
8 zeitstempel is German for "timestamp".
9
10 ---
11
12 Time's hard. Correct time is near impossible.
13
14 This crate has one purpose: give me a timestamp as an integer, coming from a monotonic clock
15 source, include time across suspend/hibernation of the host machine and let me compare it to
16 other timestamps.
17
18 It becomes the developer's responsibility to only compare timestamps obtained from this clock source.
19 Timestamps are not comparable across operating system reboots.
20
21 # Why not `std::time::Instant`?
22
23 [`std::time::Instant`] fulfills some of our requirements:
24
25 [`std::time::Instant`]: https://doc.rust-lang.org/1.47.0/std/time/struct.Instant.html
26
27 * It's monotonic, guaranteed ([sort of][rustsource]).
28 * It can be compared to other timespans.
29
30 However:
31
32 * It can't be serialized.
33 * It's not guaranteed that the clock source it uses contains suspend/hibernation time across all operating systems.
34
35 [rustsource]: https://doc.rust-lang.org/1.47.0/src/std/time.rs.html#213-237
36
37 # Example
38
39 ```rust
40 use std::{thread, time::Duration};
41
42 let start = zeitstempel::now();
43 thread::sleep(Duration::from_millis(2));
44
45 let diff = Duration::from_nanos(zeitstempel::now() - start);
46 assert!(diff >= Duration::from_millis(2));
47 ```
48
49 # Supported operating systems
50
51 We support the following operating systems:
52
53 * Windows\*
54 * macOS
55 * Linux
56 * Android
57 * iOS
58
59 For other operating systems there's a fallback to `std::time::Instant`,
60 compared against a process-global fixed reference point.
61 We don't guarantee that measured time includes time the system spends in sleep or hibernation.
62
63 \* To use native Windows 10 functionality enable the `win10plus` feature. Otherwise it will use the fallback.
64
65 # License
66
67 MPL 2.0. See [LICENSE](LICENSE).