1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! The clock the user interface reads, instead of the system's.
//!
//! Two things on screen come from the clock rather than from mail: the date
//! column of the message list, which drops the year for anything sent this
//! year, and the throbbers that count the seconds a background operation has
//! been running. Both are why the same application state renders differently
//! at different moments, which is precisely what a snapshot test -- or a demo
//! recording that should look the same next year -- cannot have.
//!
//! [`freeze`] holds the clock still for the calling thread. It exists only in
//! builds that can want it, the tests and the `recorder` feature; everywhere
//! else [`frozen`] is a function returning `None` and the branch folds away.
use ;
use OffsetDateTime;
/// What the interface calls "now".
pub
/// How long ago `since` was.
pub
/// Nothing is ever frozen in a normal build.
thread_local!
/// Hold time still on this thread: [`now_utc`] answers `now`, and every
/// operation reports `elapsed` as its age however long it has really been
/// running.
///
/// A single age for everything is coarse, but the age is only ever rendered as
/// a throbber frame and a tenth-of-a-second counter, and a caller that wants to
/// see a different one just freezes the clock again before drawing. Per thread
/// rather than per process, so tests running next to each other -- `cargo test`
/// gives each its own thread -- cannot disturb one another.
///
/// Unused in a `recorder` build of the binary: what calls it there is the demo
/// example, which compiles this module into itself.
pub