Expand description
The route time-window gate: the reference pipeline’s tenth check.
This is the Rust family’s port of
guard_core/core/checks/implementations/time_window.py. A route’s
time_restrictions dict (start, end, optional timezone, all
"HH:MM" / IANA strings) admits requests only inside its window:
current local HH:MM in the zone (invalid zone -> UTC):
start > end: allowed when now >= start OR now <= end
(the window wraps midnight)
otherwise: allowed when start <= now <= end
missing start/end, or any evaluation error: allowed
(the reference's fail-open
except arm, captured as
normative by spec 03)The comparisons are plain "HH:MM" string comparisons, exactly the
reference’s strftime("%H:MM") ordering (lexicographic == chronological
on the zero-padded form). Zone resolution uses the IANA database
(ZoneInfo in the reference); a name the database does not know falls
back to UTC, exactly the reference’s except arm around ZoneInfo.
§Example
use guard_core_engine::time_window::{hhmm_in_zone, is_within, TimeWindow};
use chrono::TimeZone;
let window = TimeWindow { start: Some("09:00".into()), end: Some("17:00".into()), timezone: None };
assert!(is_within(&window, "09:00"));
assert!(is_within(&window, "12:30"));
assert!(!is_within(&window, "17:01"));
// A window past midnight wraps.
let night = TimeWindow { start: Some("22:00".into()), end: Some("06:00".into()), timezone: None };
assert!(is_within(&night, "23:30"));
assert!(is_within(&night, "05:59"));
assert!(!is_within(&night, "12:00"));
// The zone resolution: 12:00 UTC is 07:00 in New York (winter).
let utc = chrono::Utc.with_ymd_and_hms(2026, 1, 15, 12, 0, 0).unwrap();
assert_eq!(hhmm_in_zone(utc, Some("America/New_York")), "07:00");
// An unknown zone falls back to UTC.
assert_eq!(hhmm_in_zone(utc, Some("Mars/Olympus")), "12:00");Structs§
- Time
Window - One route’s
time_restrictions: the window bounds and the IANA zone.
Constants§
- TIME_
WINDOW_ BLOCK_ BODY - The block body the reference answers with.
- TIME_
WINDOW_ BLOCK_ STATUS - The block status the reference answers (
create_error_response(403, default_message="Access not allowed at this time")). - TIME_
WINDOW_ CHECK_ NAME - The check’s stable name (
check_name).
Functions§
- hhmm_
in_ zone - The wall-clock
"HH:MM"ofnow_utcobserved intimezone. - is_
within - The window decision against a current
"HH:MM".