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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! Canonical wall-clock for write-surface timestamp seeding.
//!
//! Every write surface that stamps `created` / `updated` (or a log entry's
//! timestamp) seeds it from [`now`] so all of them agree on one representation:
//! the current instant as a fixed-offset (UTC) [`DateTime`]. This is the type
//! [`crate::Frontmatter::created`] / [`crate::Frontmatter::updated`] already
//! hold, so callers assign it directly with no string round-trip.
//!
//! Keeping this in `dbmd-core` (rather than re-deriving it per CLI handler)
//! means `dbmd write`, `dbmd fm init`, `dbmd fm set`, and `dbmd log append` all
//! compute "now" the same way from one place — and the thin CLI carries no
//! bespoke calendar logic.
//!
//! ## Reproducibility hook: `DBMD_NOW`
//!
//! Because every write surface seeds its timestamps from this one function, it
//! is also the one place to pin the clock for **deterministic, byte-for-byte**
//! output. When the `DBMD_NOW` environment variable is set to an RFC3339
//! timestamp, [`now`] returns that instant verbatim instead of the wall clock,
//! so a scripted sequence of `dbmd write` / `fm set` / `log` invocations
//! produces identical `created`/`updated` fields, identical `index.md` /
//! `index.jsonl` (whose own `updated` is the max over their records), and
//! identical `log.md` headers on every run. This is the same family of build
//! hook as `SOURCE_DATE_EPOCH`: unset, behaviour is exactly the wall clock it
//! always was (zero product impact); set, the toolkit is reproducible — which
//! the agent-eval golden harness (`crates/dbmd-cli/tests/agent_eval.rs`) relies
//! on to commit `EXPECTED/` trees that pin the curator's output. A malformed
//! `DBMD_NOW` is ignored (falls back to the wall clock) rather than aborting an
//! otherwise-valid write.
use ;
/// Environment variable that pins [`now`] to a fixed RFC3339 instant. See the
/// module docs (`## Reproducibility hook`). Unset ⇒ wall clock.
pub const NOW_OVERRIDE_ENV: &str = "DBMD_NOW";
/// The current instant as a fixed-offset (UTC) timestamp.
///
/// Returns `DateTime<FixedOffset>` — the canonical type the universal `created`
/// / `updated` frontmatter fields and the log entry timestamp hold — so write
/// surfaces seed it without any RFC3339 string round-trip. Resolution is
/// chrono's native (sub-second); the canonical writers render it to RFC3339 on
/// the way to disk.
///
/// If [`NOW_OVERRIDE_ENV`] (`DBMD_NOW`) is set to a parseable RFC3339 timestamp,
/// that fixed instant is returned instead of the wall clock — the deterministic
/// reproducibility hook (see module docs). An unset or unparseable value falls
/// back to the wall clock, so the default path is unchanged.
/// Read and parse [`NOW_OVERRIDE_ENV`]. `None` when unset or unparseable (the
/// caller then uses the wall clock). Normalized to the UTC (zero) offset to
/// match the wall-clock path, so downstream RFC3339 rendering is offset-stable
/// regardless of the offset the override was written with.