trading_calendar/
error.rs

1//! Error types for the trading calendar
2
3use chrono::NaiveDate;
4use thiserror::Error;
5
6/// Errors that can occur when using the trading calendar
7#[derive(Error, Debug)]
8pub enum CalendarError {
9    /// Date is outside the supported range
10    #[error("Date {0} is outside supported range (2020-2030). Please use a date within the supported range.")]
11    DateOutOfRange(NaiveDate),
12
13    /// Invalid time provided
14    #[error("Invalid time for market operation: {0}. Times must be in 24-hour format (HH:MM:SS).")]
15    InvalidTime(String),
16
17    /// No trading day found within search period
18    #[error("No trading day found within search period. The market may be closed for an extended period.")]
19    NoTradingDayFound,
20
21    /// Invalid date calculation
22    #[error("Invalid date calculation: {0}")]
23    InvalidDateCalculation(String),
24
25    /// Invalid configuration
26    #[error("Invalid configuration: {0}")]
27    InvalidConfiguration(String),
28
29    /// Invalid session times
30    #[error("Invalid session: end time must be after start time for regular sessions")]
31    InvalidSession,
32}
33
34/// Result type alias for trading calendar operations
35pub type Result<T> = std::result::Result<T, CalendarError>;