#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod cmp;
pub mod conventions;
pub mod convert;
pub mod error;
pub mod parser;
pub mod prelude;
pub mod serde_impl;
use chrono::{DateTime, Utc};
use positive::Positive;
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
pub const EPSILON: Decimal = dec!(1e-16);
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[must_use = "Financial expiration results must be used for correct pricing calculations."]
pub enum ExpirationDate {
Days(Positive),
DateTime(DateTime<Utc>),
}
impl ExpirationDate {
thread_local! {
static REFERENCE_DATETIME: std::cell::RefCell<Option<DateTime<Utc>>> = const { std::cell::RefCell::new(None) };
}
pub fn set_reference_datetime(dt: Option<DateTime<Utc>>) {
Self::REFERENCE_DATETIME.with(|cell| {
*cell.borrow_mut() = dt;
});
}
#[must_use = "Retrieving the reference datetime has no effect if the result is ignored."]
pub fn get_reference_datetime() -> Option<DateTime<Utc>> {
Self::REFERENCE_DATETIME.with(|cell| *cell.borrow())
}
}