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
147
148
149
150
151
//! Calendar availability and scheduling calculations across constraints.
//!
//! A [`Request`] goes in — the current instant, what is to be booked, the
//! participants and their calendars, and the caller's final rule list — and a
//! [`Response`] comes out: the times that can be booked, who could take each one,
//! and the travel to reserve. The engine is a pure function of its input: `now`
//! is an argument, there is no clock and no I/O, and the same request against the
//! same versions gives the same answer everywhere.
//!
//! [`Engine`] holds the time zone database and the request limits. It is built
//! once and reused, and it is the only thing that resolves a request's zone and
//! calendar names, which is what keeps a request a plain value a caller can build
//! and store without either.
//!
//! # Quickstart
//!
//! One person, one 30-minute booking, over a week of weekdays with ten-minute
//! buffers and four hours' notice:
//!
//! ```
//! use opportune::Engine;
//! use opportune::model::{Goal, Participant, Request, Requirement, Span, Term};
//! use opportune::presets;
//! use opportune::time::{
//! Date, Duration, Instant, RuleZone, TimeOfDay, Weekday, Weekdays, ZoneName,
//! };
//!
//! # #[cfg(feature = "bundled-tzdb")] {
//! let zone = ZoneName::new("Europe/London").unwrap();
//! let now = Instant::from_utc(Date::new(2027, 6, 14).unwrap(), TimeOfDay::new(7, 0).unwrap()).unwrap();
//! let until = Instant::from_utc(Date::new(2027, 6, 19).unwrap(), TimeOfDay::new(0, 0).unwrap()).unwrap();
//! let mut request = Request::new(
//! now,
//! Goal::single(
//! zone.clone(),
//! Span::new(now, until).unwrap(),
//! Duration::from_minutes(30),
//! Requirement::new(vec![Term::person("rich")]),
//! ),
//! );
//! request
//! .participants
//! .push(Participant::new("rich", zone).with_calendar(Vec::new()));
//! request.rules.push(presets::business_hours(
//! RuleZone::Participant,
//! Weekdays::range(Weekday::Monday, Weekday::Friday),
//! TimeOfDay::new(9, 0).unwrap(),
//! TimeOfDay::new(17, 0).unwrap(),
//! ).unwrap());
//! request.rules.push(presets::buffers(Duration::from_minutes(10), Duration::from_minutes(10)));
//! request.rules.push(presets::min_notice(Duration::from_hours_minutes(4, 0)));
//!
//! let response = Engine::builder().build().unwrap().find_availability(&request).unwrap();
//! assert!(!response.offers.is_empty());
//! # }
//! ```
//!
//! # Entry points
//!
//! [`Engine::find_availability`] books forwards: every candidate start that the
//! participants' calendars, rules, caps and rest allow, each with who could take
//! it. [`Engine::check_slot`] judges one proposed booking at confirmation time,
//! against the same rules and calendars, reporting every failing reason.
//! [`Engine::validate`] reports the request's structural errors and its warnings
//! before any availability is computed, and [`Engine::required_ranges`] says which
//! calendar and occurrence data the caller has to fetch. With the default
//! `bundled-tzdb` feature the same four are also free functions using a default
//! engine.
//!
//! # Time zone databases
//!
//! The database is always an explicit choice, never the host's: results that
//! depend on the machine are not reproducible. `EngineBuilder::tzdb_bundled`
//! uses the database compiled into the binary (the default with the
//! `bundled-tzdb` feature), and `EngineBuilder::tzdb_dir` reads a directory of
//! `TZif` files, labelling it from its `+VERSION` file or from the label the
//! caller passes. Without `bundled-tzdb` there is no default engine and building
//! one fails with `tzdb_not_configured` until a directory is given.
//!
//! # Rule kinds
//!
//! Rules are typed data with fixed meaning, and the caller supplies the final
//! list: `window`, `blackout`, `clearance`, `lead_time`, `status_policy`, `rest`
//! and `cap`. [`presets`] builds the common ones into [`Rule`] values, and the
//! builders in [`model`] and [`time`] cover the rest.
//!
//! # Reasons and errors
//!
//! Every excluded start carries structured [`reasons`] when the request asks for
//! an explanation, each with a stable [`ReasonCode`]; [`ReasonCode::ALL`] is the
//! registry, in the precedence order a participant's first failing reason
//! follows. Every failure is a typed [`Error`] whose `code()` is stable across
//! releases, and a request that [`Engine::validate`] rejects comes back with
//! [`Diagnostic`] findings that name the request field at fault.
//!
//! # Feature flags
//!
//! `bundled-tzdb` (default) compiles the time zone database into the crate and
//! provides the free functions. Turning it off leaves the core with a
//! caller-supplied database only, which is what a strict license build or a
//! `wasm32` build with its own data uses.
//!
//! This crate is pure Rust: the Python bindings live in `opportune-py`, which
//! depends on this crate by path and re-exports [`VERSION`] as
//! `opportune.__version__`.
// Exposed for `opportune-testkit`'s brute-force oracle, which compares its own
// assignment against the engine's. Hidden from the documented surface so its
// `Term` does not read as a second, competing definition beside `model::Term`;
// its assignments are an implementation detail of the engine, not a contract a
// caller builds against.
pub use ;
pub use ;
pub use ;
pub use Limits;
pub use ;
pub use ;
/// The crate version, re-exported by the `opportune-py` bindings as
/// `opportune.__version__`.
pub const VERSION: &str = env!;