Skip to main content

Calendar

Struct Calendar 

Source
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 str

One 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

Source

pub fn new( name: impl Into<String>, weekmask: [bool; 7], rules: Vec<HolidayRule>, trading_hours: Option<TradingHours>, ) -> Self

Source

pub fn with_type( name: impl Into<String>, market_type: &'static str, weekmask: [bool; 7], rules: Vec<HolidayRule>, trading_hours: Option<TradingHours>, ) -> Self

Source

pub fn with_early_closes(self, ec: Vec<EarlyCloseRule>) -> Self

Builder: attach early-close rules.

Source

pub fn with_schedules(self, schedules: Vec<CalendarSchedule>) -> Self

Builder: attach date-effective schedules sorted by effective date.

Source

pub fn early_close_for(&self, date: NaiveDate) -> Option<NaiveTime>

Local early-close time for date, if any.

Source

pub fn holidays(&self, year: i32) -> Arc<BTreeSet<NaiveDate>>

Source

pub fn holidays_between( &self, start: NaiveDate, end: NaiveDate, ) -> BTreeSet<NaiveDate>

Source

pub fn is_holiday(&self, d: NaiveDate) -> bool

Source

pub fn is_business_day(&self, d: NaiveDate) -> bool

Source

pub fn next_business_day(&self, d: NaiveDate) -> NaiveDate

Source

pub fn previous_business_day(&self, d: NaiveDate) -> NaiveDate

Source

pub fn business_days_between(&self, start: NaiveDate, end: NaiveDate) -> i64

Source

pub fn business_day_range( &self, start: NaiveDate, end: NaiveDate, ) -> Vec<NaiveDate>

Source

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.

Source

pub fn next_open(&self, when: DateTime<Utc>) -> Option<DateTime<Utc>>

Source

pub fn next_close(&self, when: DateTime<Utc>) -> Option<DateTime<Utc>>

Source

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.

Source

pub fn extended_sessions_between( &self, start: NaiveDate, end: NaiveDate, ) -> Vec<(&'static str, DateTime<Utc>, DateTime<Utc>)>

Named non-regular trading windows for every business day in [start, end] (inclusive), such as pre-open and after-close.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.