pub struct Calendar {
pub name: String,
pub market_type: &'static str,
pub weekmask: [bool; 7],
pub rules: Vec<HolidayRule>,
pub trading_hours: Option<TradingHours>,
pub schedules: Vec<CalendarSchedule>,
pub early_closes: Vec<EarlyCloseRule>,
/* private fields */
}Expand description
A holiday calendar with optional trading hours and a market classification.
Fields§
§name: String§market_type: &'static strOne of the MARKET_TYPES entries, aligned with finance-enums MarketType variants.
weekmask: [bool; 7]§rules: Vec<HolidayRule>§trading_hours: Option<TradingHours>§schedules: Vec<CalendarSchedule>§early_closes: Vec<EarlyCloseRule>Days when the venue closes earlier than usual. Each rule resolves to at most one date per year, paired with a local close time that replaces the normal session close on that date.
Implementations§
Source§impl Calendar
impl Calendar
pub fn new( name: impl Into<String>, weekmask: [bool; 7], rules: Vec<HolidayRule>, trading_hours: Option<TradingHours>, ) -> Self
pub fn with_type( name: impl Into<String>, market_type: &'static str, weekmask: [bool; 7], rules: Vec<HolidayRule>, trading_hours: Option<TradingHours>, ) -> Self
Sourcepub fn with_early_closes(self, ec: Vec<EarlyCloseRule>) -> Self
pub fn with_early_closes(self, ec: Vec<EarlyCloseRule>) -> Self
Builder: attach early-close rules.
Sourcepub fn with_schedules(self, schedules: Vec<CalendarSchedule>) -> Self
pub fn with_schedules(self, schedules: Vec<CalendarSchedule>) -> Self
Builder: attach date-effective schedules sorted by effective date.
Sourcepub fn early_close_for(&self, date: NaiveDate) -> Option<NaiveTime>
pub fn early_close_for(&self, date: NaiveDate) -> Option<NaiveTime>
Local early-close time for date, if any.
pub fn holidays(&self, year: i32) -> Arc<BTreeSet<NaiveDate>>
pub fn holidays_between( &self, start: NaiveDate, end: NaiveDate, ) -> BTreeSet<NaiveDate>
pub fn is_holiday(&self, d: NaiveDate) -> bool
pub fn is_business_day(&self, d: NaiveDate) -> bool
pub fn next_business_day(&self, d: NaiveDate) -> NaiveDate
pub fn previous_business_day(&self, d: NaiveDate) -> NaiveDate
pub fn business_days_between(&self, start: NaiveDate, end: NaiveDate) -> i64
pub fn business_day_range( &self, start: NaiveDate, end: NaiveDate, ) -> Vec<NaiveDate>
Sourcepub fn is_open(&self, when: DateTime<Utc>) -> bool
pub fn is_open(&self, when: DateTime<Utc>) -> bool
True iff the venue is currently in any trading session.
For sessions that span midnight, the trading-day check considers both
the local calendar day of when and the next local calendar day, so a
Sun-evening CME open correctly maps to Mon’s trading day. If an
early-close is in effect for that trading day, the last session’s
close is shortened.
pub fn next_open(&self, when: DateTime<Utc>) -> Option<DateTime<Utc>>
pub fn next_close(&self, when: DateTime<Utc>) -> Option<DateTime<Utc>>
Sourcepub fn sessions_between(
&self,
start: NaiveDate,
end: NaiveDate,
) -> Vec<(DateTime<Utc>, DateTime<Utc>)>
pub fn sessions_between( &self, start: NaiveDate, end: NaiveDate, ) -> Vec<(DateTime<Utc>, DateTime<Utc>)>
All (open, close) UTC instants for every business day in
[start, end] (inclusive). Each business day contributes one entry
per trading session, with the last session’s close adjusted for any
early-close rule. Returns an empty vector when no trading hours are
configured.