pub struct TemporalContext { /* private fields */ }Expand description
Unified temporal-context bundle for business-day / holiday awareness.
Arc<TemporalContext> is the intended ownership model — construct once
in the orchestrator, clone into each generator via
generator.set_temporal_context(Arc::clone(&ctx)).
Implementations§
Source§impl TemporalContext
impl TemporalContext
Sourcepub fn new(region: Region, start_date: NaiveDate, end_date: NaiveDate) -> Self
pub fn new(region: Region, start_date: NaiveDate, end_date: NaiveDate) -> Self
Build a temporal context that covers the inclusive span
[start_date, end_date] in the given region.
Holiday calendars are loaded per-year and merged into a single calendar so multi-year pipelines work correctly.
Convenience wrapper around TemporalContext::new that returns an
Arc.
Sourcepub fn start_date(&self) -> NaiveDate
pub fn start_date(&self) -> NaiveDate
Inclusive start of the covered span.
Sourcepub fn calculator(&self) -> &BusinessDayCalculator
pub fn calculator(&self) -> &BusinessDayCalculator
Access the wrapped BusinessDayCalculator directly. Useful when
callers need settlement-rule or half-day APIs the shortcuts below
don’t expose.
Sourcepub fn is_business_day(&self, date: NaiveDate) -> bool
pub fn is_business_day(&self, date: NaiveDate) -> bool
Is date a business day in this region?
Sourcepub fn adjust_to_business_day(&self, date: NaiveDate) -> NaiveDate
pub fn adjust_to_business_day(&self, date: NaiveDate) -> NaiveDate
Snap date forward to the next business day (inclusive — if date
is already a business day, it’s returned unchanged). Used by
document-flow generators to ensure posting dates never land on a
weekend or holiday.
Sourcepub fn adjust_to_previous_business_day(&self, date: NaiveDate) -> NaiveDate
pub fn adjust_to_previous_business_day(&self, date: NaiveDate) -> NaiveDate
Snap date backward to the previous business day (inclusive).
Sourcepub fn sample_business_day_in_range<R: Rng + ?Sized>(
&self,
rng: &mut R,
start: NaiveDate,
end: NaiveDate,
) -> NaiveDate
pub fn sample_business_day_in_range<R: Rng + ?Sized>( &self, rng: &mut R, start: NaiveDate, end: NaiveDate, ) -> NaiveDate
Sample a business day uniformly from [start, end] (inclusive).
Implementation strategy: sample a raw offset from the RNG, then snap
forward to the next business day. This preserves existing RNG call
counts for unit tests that rely on a specific draw sequence — each
sample consumes exactly one rng.random_range(...) call, just like
the pre-v3.4.1 raw rng.random_range(0..=days_range) pattern.
If snapping forward would exceed end, the result is clamped to the
nearest preceding business day (to guarantee the result stays in
range).
Trait Implementations§
Source§impl Clone for TemporalContext
impl Clone for TemporalContext
Source§fn clone(&self) -> TemporalContext
fn clone(&self) -> TemporalContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TemporalContext
impl RefUnwindSafe for TemporalContext
impl Send for TemporalContext
impl Sync for TemporalContext
impl Unpin for TemporalContext
impl UnsafeUnpin for TemporalContext
impl UnwindSafe for TemporalContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.