logistics.delivery-date
Estimated dispatch and delivery dates from order time, dispatch cut-off, service days, weekends and UK bank holidays.
1.0.0 · published 2026-10-03 by charlie · Anterra
Pinned by 26 tests, run in TypeScript, Python and Rust.
What it does
The "order in the next 2 hours for delivery on Thursday" calculation. An order goes out the same day when it is placed on a working day strictly before the cut-off time; otherwise it goes out on the next working day. Delivery is `serviceDays` working days after dispatch, so 1 is next-day delivery and 0 is same-day.
Working days are Monday to Friday, less the UK bank holidays of `region` (from `dates.bank-holidays`) and any `closures` the caller adds. The arithmetic is `dates.add-business-days`.
For example
delivery_date(2026-09-23, 10:00, 15:00, 1, england-and-wales, )→ dispatch date 2026-09-23, delivery date 2026-09-24, same day dispatch true a Wednesday morning order goes out today and arrives tomorrowdelivery_date(2026-09-23, 14:59, 15:00, 1, england-and-wales, )→ dispatch date 2026-09-23, delivery date 2026-09-24, same day dispatch true one minute before the cut-off still makes itdelivery_date(2026-09-23, 15:00, 15:00, 1, england-and-wales, )→ dispatch date 2026-09-24, delivery date 2026-09-25, same day dispatch false exactly at the cut-off misses it
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
def delivery_date(order_date: str, order_time: str, cut_off: str, service_days: int, region: Optional[UkRegion], closures: Sequence[str]) -> DeliveryEstimate
| order_date | date | the local date the order was placed, at the dispatching warehouse |
| order_time | string | local time the order was placed, 24-hour HH:MM |
| cut_off | string | orders placed strictly before this local time go out the same working day, HH:MM |
| service_days | int | working days in transit: 1 for next day, 0 for same-day delivery |
| region | UkRegion? | UK bank holidays to skip, as gov.uk divides them; null for none |
| closures | date[] | other non-working dates (warehouse or carrier closures, another country's holidays) |
| returns | DeliveryEstimate |
The type it declares, generated into your project
@dataclass(frozen=True)
class DeliveryEstimate:
"""When the parcel leaves and when it should arrive."""
dispatch_date: str
delivery_date: str
#: true when the order made the day's cut-off
same_day_dispatch: bool
Your code names it in one line, in the file that uses it
from fune.logistics.delivery_date import delivery_date # logistics.delivery-date@^1
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import re
from typing import List, Optional, Sequence
from .dates_add_business_days import add_business_days ← from dates.add-business-days ^1.0.0 · built alongside by fune
from .dates_bank_holidays import UkRegion, bank_holidays ← from dates.bank-holidays ^1.0.0 · built alongside by fune
from .dates_day_of_week import day_of_week ← from dates.day-of-week ^1.0.0 · built alongside by fune
from .logistics_delivery_date_types import DeliveryEstimate
_TIME = re.compile(r"([01][0-9]|2[0-3]):[0-5][0-9]")
def _estimate(
order_date: str, order_time: str, cut_off: str, service_days: int, holidays: Sequence[str]
) -> DeliveryEstimate:
working = day_of_week(order_date) <= 5 and order_date not in holidays
# HH:MM compares correctly as text. Strictly before: 15:00 misses a 15:00 cut-off.
same_day = working and order_time < cut_off
dispatch = order_date if same_day else add_business_days(order_date, 1, holidays)
return DeliveryEstimate(
dispatch_date=dispatch,
delivery_date=add_business_days(dispatch, service_days, holidays),
same_day_dispatch=same_day,
)
def delivery_date(
order_date: str,
order_time: str,
cut_off: str,
service_days: int,
region: Optional[UkRegion],
closures: Sequence[str],
) -> DeliveryEstimate:
"""When an order leaves the warehouse and when it should arrive: same
working day if placed before the cut-off, then service_days working days in
transit, skipping weekends, the region's bank holidays and the caller's
closures."""
if not isinstance(order_time, str) or not _TIME.fullmatch(order_time):
raise ValueError('orderTime must be a 24-hour time HH:MM, received "%s"' % (order_time,))
if not isinstance(cut_off, str) or not _TIME.fullmatch(cut_off):
raise ValueError('cutOff must be a 24-hour time HH:MM, received "%s"' % (cut_off,))
if isinstance(service_days, bool) or not isinstance(service_days, int):
raise TypeError("serviceDays must be an integer, received %r" % (service_days,))
if service_days < 0:
raise ValueError("serviceDays must not be negative, received %d" % service_days)
day_of_week(order_date) # validates the date before its year is used
holidays: List[str] = list(closures)
last_year = int(order_date[0:4])
if region is not None:
holidays.extend(h.date for h in bank_holidays(region, last_year))
# Load each later year the estimate reaches: an order on 31 December must
# skip next year's New Year's Day. More holidays only move the answer later,
# so this settles.
while True:
result = _estimate(order_date, order_time, cut_off, service_days, holidays)
reached = int(result.delivery_date[0:4])
if region is None or reached <= last_year:
return result
for year in range(last_year + 1, reached + 1):
holidays.extend(h.date for h in bank_holidays(region, year))
last_year = reachedInstall
fune build
With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 3 dependencies, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add logistics.delivery-date
The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./logistics.delivery-date-1.0.0-python.fune, or fetch it from a terminal with fune pull logistics.delivery-date@1.0.0:python.
The whole function, every language, is one file too: logistics.delivery-date-1.0.0.fune, 20,130 bytes, sha256 bd62d3c93df138ca8f79b8fc80b6870308c59a14b2e3ba36a8cf803ea728edc4. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
# fune: before logistics.delivery-date
after — your function gets the result and the arguments, and returns the final result.
# fune: after logistics.delivery-date
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
# fune: replace dates.add-business-days in logistics.delivery-date
# fune: replace dates.bank-holidays in logistics.delivery-date
# fune: replace dates.day-of-week in logistics.delivery-date
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show logistics.delivery-date --steps.
# fune: step logistics.delivery-date after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| a Wednesday morning order goes out today and arrives tomorrow | 2026-09-23, 10:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-09-23, delivery date 2026-09-24, same day dispatch true |
| one minute before the cut-off still makes it | 2026-09-23, 14:59, 15:00, 1, england-and-wales, | → | dispatch date 2026-09-23, delivery date 2026-09-24, same day dispatch true |
| exactly at the cut-off misses it | 2026-09-23, 15:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-09-24, delivery date 2026-09-25, same day dispatch false |
| Friday after the cut-off goes out on Monday | 2026-09-25, 16:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-09-28, delivery date 2026-09-29, same day dispatch false |
| a Saturday order goes out on Monday even before the cut-off | 2026-09-26, 09:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-09-28, delivery date 2026-09-29, same day dispatch false |
| Maundy Thursday after the cut-off skips Good Friday, the weekend and Easter Monday | 2026-04-02, 16:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-04-07, delivery date 2026-04-08, same day dispatch false |
| Easter Monday is not a holiday in Scotland | 2026-04-06, 10:00, 15:00, 1, scotland, | → | dispatch date 2026-04-06, delivery date 2026-04-07, same day dispatch true |
| Easter Monday is a holiday in England and Wales | 2026-04-06, 10:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-04-07, delivery date 2026-04-08, same day dispatch false |
| Christmas Eve, two days: skips Christmas, the weekend and the Boxing Day substitute | 2026-12-24, 12:00, 15:00, 2, england-and-wales, | → | dispatch date 2026-12-24, delivery date 2026-12-30, same day dispatch true |
| New Year's Eve: next year's New Year's Day is skipped too | 2026-12-31, 10:00, 15:00, 1, england-and-wales, | → | dispatch date 2026-12-31, delivery date 2027-01-04, same day dispatch true |
Show the other 16 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| New Year's Eve in Scotland also skips the 2nd January substitute | 2026-12-31, 10:00, 15:00, 1, scotland, | → | dispatch date 2026-12-31, delivery date 2027-01-05, same day dispatch true |
| five-day service over the August bank holiday | 2026-08-24, 09:00, 15:00, 5, england-and-wales, | → | dispatch date 2026-08-24, delivery date 2026-09-01, same day dispatch true |
| same-day service arrives on the dispatch day | 2026-09-23, 10:00, 15:00, 0, england-and-wales, | → | dispatch date 2026-09-23, delivery date 2026-09-23, same day dispatch true |
| same-day service ordered too late arrives the next working day | 2026-09-23, 15:30, 15:00, 0, england-and-wales, | → | dispatch date 2026-09-24, delivery date 2026-09-24, same day dispatch false |
| no region: Christmas Day is a working day | 2026-12-24, 16:00, 15:00, 1, —, | → | dispatch date 2026-12-25, delivery date 2026-12-28, same day dispatch false |
| a closure in transit is skipped | 2026-09-23, 10:00, 15:00, 2, —, 2026-09-24 | → | dispatch date 2026-09-23, delivery date 2026-09-28, same day dispatch true |
| a closure on the order day delays dispatch | 2026-09-23, 10:00, 15:00, 1, —, 2026-09-23 | → | dispatch date 2026-09-24, delivery date 2026-09-25, same day dispatch false |
| a midnight cut-off means nothing goes the same day | 2026-09-23, 00:00, 00:00, 1, england-and-wales, | → | dispatch date 2026-09-24, delivery date 2026-09-25, same day dispatch false |
| a cut-off of 23:59 | 2026-09-23, 23:58, 23:59, 1, england-and-wales, | → | dispatch date 2026-09-23, delivery date 2026-09-24, same day dispatch true |
| an estimate reaching a year gov.uk has not published | 2028-12-29, 10:00, 15:00, 1, england-and-wales, | → | error: no bank holiday data for england-and-wales in 2029 |
| a 12-hour time | 2026-09-23, 3pm, 15:00, 1, england-and-wales, | → | error: orderTime must be a 24-hour time HH:MM |
| 24:00 is not a time of day | 2026-09-23, 24:00, 15:00, 1, england-and-wales, | → | error: orderTime must be a 24-hour time HH:MM |
| a cut-off with 60 minutes | 2026-09-23, 10:00, 15:60, 1, england-and-wales, | → | error: cutOff must be a 24-hour time HH:MM |
| negative service days | 2026-09-23, 10:00, 15:00, -1, england-and-wales, | → | error: serviceDays must not be negative |
| an impossible order date | 2026-02-30, 10:00, 15:00, 1, england-and-wales, | → | error: 2026-02-30 |
| an unknown region | 2026-09-23, 10:00, 15:00, 1, wales, | → | error: unknown region "wales" |
More from the author
## Decisions
- **Before, not at.** An order at 15:00 exactly misses a 15:00 cut-off, matching "order before 3pm". Times are the warehouse's local clock, HH:MM in 24 hours; converting a customer's time zone is the caller's job. - **Weekend and holiday orders** are dispatched on the next working day whatever the time. - **Holidays in the right years.** Bank holidays are loaded for the order's year and then for each later year the estimate reaches, so an order on 31 December skips New Year's Day. An estimate that reaches a year gov.uk has not published yet is an error from `dates.bank-holidays` rather than a guess that treats unknown holidays as working days. - **One calendar for both ends.** The same working days apply to dispatch and delivery. A carrier that delivers on Saturdays, or a delivery into a region with different holidays, needs its own call or its own `closures`. - **An estimate, not a promise.** It knows nothing about carrier delays, remote-area surcharges, or the actual collection time.
## Sources
UK bank holidays: gov.uk, https://www.gov.uk/bank-holidays (via `dates.bank-holidays`).
Files
| Path | Bytes |
|---|---|
| README.md | 1,665 |
| impl/python.py | 2,798 |
| impl/rust.rs | 3,733 |
| impl/typescript.ts | 2,692 |
| vectors.json | 5,525 |