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
//! Timezone-aware cron schedule helpers, shared by the scheduler (when a
//! job is due / its next run) and the `cron_manage` tool + CLI (validating
//! a timezone and showing the user the upcoming run times).
//!
//! Two things every caller must know about our cron format:
//! * The user/agent writes a **5-field** expression (`min hour dom mon
//! dow`); we prepend `"0 "` for the seconds field the `cron` crate
//! wants. That prefix is also why `@daily`/`@hourly` macros don't work
//! through us — `"0 @daily"` is not a valid expression.
//! * Day-of-week is **1-7 = Sun-Sat** in the `cron` crate (1=Sunday,
//! 7=Saturday; `0` is rejected). Day and month *names* (`Sun`-`Sat`,
//! `Mon-Fri`, `Jan-Mar`) are accepted and unambiguous.
//!
//! Schedules are interpreted in the job's timezone's **wall clock** and
//! converted back to UTC for storage/comparison, so "09:00 America/New_York"
//! fires at the right instant year-round (DST-aware).
use ;
use Tz;
use Schedule;
use FromStr;
/// Parse a job timezone string (e.g. `"America/New_York"`, `"UTC"`) into a
/// [`Tz`]. Returns `None` for an unknown zone so callers can reject it at
/// creation rather than silently falling back and surprising the user.
/// Parse a 5-field cron expression, prepending the seconds field the `cron`
/// crate requires. `None` if the expression is malformed.
/// The next `n` fire times for a 5-field cron expression, interpreted in
/// `tz`'s wall clock (DST-aware), returned as tz-local datetimes for
/// display. Empty if the expression is malformed or has no future runs.
/// The next fire time as a UTC instant: the schedule's next wall-clock match
/// in `tz`, converted back to UTC. This is what the scheduler stores in
/// `next_run_at` and compares against `Utc::now()`.
/// Render the next `n` run times as indented `- <when>` lines in the job's
/// timezone, for the confirmation message the tool/CLI shows after creating
/// a job. The agent (and user) read this back to verify the schedule means
/// what they intended — the cheapest guard against the day-of-week footgun.
/// Falls back to a clear notice if no runs could be computed.