MonkeyLoader All articles
Performance

Friday or Bust: A Delivery Estimator That Reads the Bank Holiday Calendar

MonkeyLoader
Friday or Bust: A Delivery Estimator That Reads the Bank Holiday Calendar

Photo: Jaggery , CC BY-SA 2.0, via Wikimedia Commons

A shopper does not care about your carrier cut-off matrix. They care about one thing: if I order this now, will it arrive by Friday? A good delivery estimator answers that question in a few hundred milliseconds, using the right bank holiday calendar for the postcode, and then gets out of the way.

The temptation is to load the full UK holiday calendar on every product page. It is small, so why not? Because the same logic that loads a calendar today will load a carrier table tomorrow and a postcode database next week. Better to build the habit: ask for the postcode first, then fetch only the rules that apply.

Postcode first, calendar second

Put a single input on the page: postcode. Optionally a product ID if different products have different cut-offs. Do not fetch the holiday calendar until the shopper submits a valid-looking postcode. The first request goes to your own endpoint:

const res = await fetch(
  `/api/delivery-estimate?postcode=${encodeURIComponent(postcode)}&sku=${sku}`
);
const estimate = await res.json();

The server maps the postcode to a holiday region, loads that region's calendar for the relevant year, applies the carrier cut-off, and returns a date. The browser renders the answer. It never downloads holidays-2026-all-regions.json just to display a spinner.

Mapping a postcode to a holiday region

A rough starting point is the postcode area. Northern Ireland is BT. Most Scottish postcode areas are easy to list. Everything else falls back to England and Wales.

const SCOTLAND = new Set([
  'AB', 'DD', 'DG', 'EH', 'FK', 'G', 'HS', 'IV', 'KA',
  'KW', 'KY', 'ML', 'PA', 'PH', 'TD', 'ZE'
]);

export function holidayRegion(postcode: string) {
  const area = postcode.trim().toUpperCase().match(/^[A-Z]{1,2}/)?.[0];
  if (area === 'BT') return 'northern-ireland';
  if (area && SCOTLAND.has(area)) return 'scotland';
  return 'england-wales';
}

This is deliberately simple, and it has edge cases. TD15 includes Berwick-upon-Tweed, which is in England. Border postcodes deserve a proper lookup table or a postcode API. Use this snippet as a starting point, not as a promise to the customer.

The calendar itself

Store bank holidays as ISO dates by region and year. Do not store them as 'the last Monday in August' unless you enjoy date maths. A small JSON file is fine:

{
  "england-wales": [
    "2026-01-01", "2026-04-03", "2026-04-06", "2026-05-04",
    "2026-05-25", "2026-08-31", "2026-12-25", "2026-12-28"
  ],
  "scotland": [
    "2026-01-01", "2026-01-02", "2026-04-03", "2026-04-06",
    "2026-05-04", "2026-05-25", "2026-08-03", "2026-11-30",
    "2026-12-25", "2026-12-28"
  ],
  "northern-ireland": [
    "2026-01-01", "2026-03-17", "2026-04-03", "2026-04-06",
    "2026-05-04", "2026-05-25", "2026-07-13", "2026-08-31",
    "2026-12-25", "2026-12-28"
  ]
}

Keep the file under version control and have a test that fails when a year is missing. Bank holiday dates are published well in advance, but they are not generated by magic.

Working days and cut-offs

The estimator needs two inputs: the carrier's cut-off time and the number of working days the service takes. Add working days while skipping weekends and the relevant holiday set. Use Europe/London for the day comparison, or you will get an off-by-one around midnight during British Summer Time.

function londonDay(date: Date): string {
  return new Intl.DateTimeFormat('en-CA', {
    timeZone: 'Europe/London',
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  }).format(date);
}

function addWorkingDays(start: Date, days: number, holidays: Set<string>): Date {
  const d = new Date(start);
  let added = 0;
  while (added < days) {
    d.setDate(d.getDate() + 1);
    const day = d.getDay();
    if (day !== 0 && day !== 6 && !holidays.has(londonDay(d))) added++;
  }
  return d;
}

If the shopper orders after the cut-off, start from the next working day. If the next day is a bank holiday, the loop handles it. What the loop does not handle is carrier-specific exceptions, weather, or the week between Christmas and New Year when every promise gets fuzzy. That is what the fallback is for.

Cache the answer, not the whole world

Cache by postcode district, SKU and London date. A postcode district is enough for most delivery estimates; you do not need to cache per full postcode. Set a short TTL that expires at the next cut-off, and let the edge cache do the heavy lifting.

Cache-Control: public, max-age=300, s-maxage=3600

Return a small payload:

{
  "earliestDate": "2026-12-04",
  "label": "Arrives by Friday 4 December",
  "confidence": "high"
}

The label is what the shopper reads. The ISO date is what your tests assert. Keep both.

Fallbacks that do not lie

If the postcode is invalid, say so. If the holiday calendar is unavailable, do not invent a date. Show a quiet message: 'We cannot confirm the bank holiday schedule right now. Check the delivery date at checkout.' If the carrier API is down, you can fall back to a standard working-day estimate, but label it as an estimate and do not promise a date you cannot keep.

The same rule applies to regional holidays. A shopper in Belfast should not get an England and Wales estimate because your fallback defaulted to the bigger calendar. If you do not know the region, ask for a full postcode or say nothing.

The best delivery estimator is boring: it asks one question, fetches one small set of rules, returns one clear answer, and knows when to stop. Friday or bust is the shopper's question. Your job is to answer it without loading the entire calendar into the conversation.

All Articles

Related Articles

Ask Before You Compare: A Tariff Widget That Waits Its Turn

Ask Before You Compare: A Tariff Widget That Waits Its Turn

Save-Data Is a Request, Not a Verdict: Serving Leaner Bundles Without Snobbery

Save-Data Is a Request, Not a Verdict: Serving Leaner Bundles Without Snobbery

The Paper Copy Clause: Loading Print CSS Only When Someone Asks for It

The Paper Copy Clause: Loading Print CSS Only When Someone Asks for It