Skip to main content

amended

Function amended 

pub fn amended(
    base: &dyn Calendar,
    closing: &[NaiveDate],
    opening: &[NaiveDate],
) -> Result<Arc<dyn Calendar>, CalendarAmendError>
Expand description

Derives a new calendar from base, closing the dates in closing and opening those in opening.

This is how a caller says “GBLO, plus the closure announced after the shipped table was generated” without enumerating a century of UK bank holidays. DataCalendar::new is the absolute constructor — it takes the whole holiday set; this is the relative one.

§It derives, it does not amend

base is not modified and cannot be: the Calendar trait exposes no mutators. Nothing is registered, no cache is invalidated, and every holder of every calendar — base included — resolves afterwards exactly as before. The result is a value the caller passes explicitly.

The result takes a name of its own (<GBLO amended>), which the calendar [lookup] refuses. Two calendars claiming one centre and disagreeing about its holidays is the failure the registry exists to prevent; two calendars under two names is just two calendars. To make every later lookup of a centre answer with other holidays, ingest a CalendarSpec under its code with ingest_calendar instead — the one operation that rebinds a code.

§Both date sets are taken at once

Each call rebuilds the calendar’s grid, so a chain of single-date calls pays that cost per link. Taking both sets together also makes the result independent of the order the caller supplies them in.

§Cost

This is a setup-time call, not a per-query one: it reads base’s holidays out day by day over the generated horizon and builds a fresh business-day grid — roughly half a millisecond. It buys back the O(1) probe and the O(1) business-day count, which a calendar wrapping base and consulting it per query would lose. Derive once and hold the result; do not call this on a pricing path.

§Errors

CalendarAmendError::Contradictory if a date is named in both sets.

§Panics

Never. The weekend probe walks seven days from a hard-coded 2024-01-01, which is representable, as are the six days after it; a panic here would mean chrono had produced a date it cannot represent.