pub struct Calendar {
pub id: String,
pub time_windows: Vec<TimeWindow>,
pub blocked_periods: Vec<TimeWindow>,
}Expand description
Resource availability calendar.
Combines positive availability windows with negative blocked periods. If no time_windows are defined, the resource is always available (subject to blocked periods).
Fields§
§id: StringCalendar identifier.
time_windows: Vec<TimeWindow>Periods when the resource is available. Empty = always available.
blocked_periods: Vec<TimeWindow>Periods when the resource is unavailable (overrides time_windows).
Implementations§
Source§impl Calendar
impl Calendar
Sourcepub fn new(id: impl Into<String>) -> Self
pub fn new(id: impl Into<String>) -> Self
Creates an empty calendar (no constraints = always available).
Sourcepub fn always_available(id: impl Into<String>) -> Self
pub fn always_available(id: impl Into<String>) -> Self
Creates a calendar that is always available.
Sourcepub fn with_window(self, start_ms: i64, end_ms: i64) -> Self
pub fn with_window(self, start_ms: i64, end_ms: i64) -> Self
Adds an availability window.
Sourcepub fn with_blocked(self, start_ms: i64, end_ms: i64) -> Self
pub fn with_blocked(self, start_ms: i64, end_ms: i64) -> Self
Adds a blocked period.
Sourcepub fn is_working_time(&self, time_ms: i64) -> bool
pub fn is_working_time(&self, time_ms: i64) -> bool
Whether a timestamp is within working time.
Returns true if the timestamp is in an availability window
(or no windows are defined) AND not in any blocked period.
Sourcepub fn next_available_time(&self, from_ms: i64) -> Option<i64>
pub fn next_available_time(&self, from_ms: i64) -> Option<i64>
Finds the next available time at or after from_ms.
Returns from_ms if already available, or the start of the
next availability window that isn’t blocked.
Returns None if no future availability exists.
Sourcepub fn available_time_in_range(&self, start_ms: i64, end_ms: i64) -> i64
pub fn available_time_in_range(&self, start_ms: i64, end_ms: i64) -> i64
Computes total available time within a range [start, end).