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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more