Skip to content

Recheck a booking date before accepting it

Build a date form that checks your business weekday, holiday, and closure policy again on the server.

Working example

ParseAPI
Node

Set up ParseAPI

Set PARSEAPI_KEY in your server environment. Use Node.js 22 or later.

Terminal
export PARSEAPI_KEY='YOUR_SECRET_API_KEY'
Get an API key ↗

Accept dates that fit your business calendar

A date picker can collect a valid date without knowing whether your business is open. Build a booking date form that checks the submitted date on the server and explains why it is accepted or needs changing.

This example offers weekday appointments in America/New_York, closes on US federal public holidays and December 24, 2026, and accepts dates from tomorrow through the next 180 days. These are explicit business rules. Passing them does not reserve a slot or establish staff capacity.

1. Collect one appointment date

Use a named date input so the submitted value reaches the server as date:

JavaScript
const form = `<form method="post" action="/">
  <label for="date">Appointment date</label>
  <input id="date" name="date" type="date" required
    min="${isoDay(today + 1)}" max="${isoDay(today + 180)}"
    value="${escape(fields.date ?? isoDay(today + 1))}"
    aria-describedby="policy">
  <p id="policy" class="note">Monday-Friday. US federal holidays and
    December 24, 2026 are closed. Business time zone: America/New_York.</p>
  <button type="submit">Submit date</button>
</form>`;

The input's bounds guide the person choosing a date. The server repeats those bounds using the business time zone, then rejects weekends and the business's own closed dates. A caller can edit browser constraints, so the submit handler owns the policy.

The complete app uses Node's HTTP server and a secret PARSEAPI_KEY on the server. It uses Node's built-in fetch, with one holiday attempt per submission and no package dependency.

2. Recheck the submitted date with Holiday

For a candidate weekday, request GET /holiday/US/{date} with the exact submitted date. The secret key stays in a header, and X-API-Version: 2.3.0 selects the response contract:

JavaScript
const url = new URL(`/holiday/${encodeURIComponent(country)}/${encodeURIComponent(date)}`, 'https://api.parseapi.com');
const timeout = AbortSignal.timeout(8000);
const response = await fetcher(url, {
  headers: { 'X-API-Key': apiKey.trim(), 'X-API-Version': '2.3.0' },
  signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
  redirect: 'error',
});
if (!response.ok) throw new Error('The holiday calendar could not be checked.');
const calendar = await response.json();

The small createClient function applies an eight-second deadline and the submission's cancellation signal without automatic retries. The date-policy function still accepts an injected client for testing.

The response identifies country and date, with holiday containing a published holiday or null. The complete source checks that context before using the answer. A missing field or failed request leaves the date unaccepted.

This example uses the US federal calendar. Choose the holiday scope your business actually follows before adapting it to another country or a regional calendar.

3. Turn the holiday into an acceptance decision

A public holiday closes this business. An observance does not, and holiday: null means the calendar has no holiday for that date:

JavaScript
const holiday = calendar.holiday;
if (holiday?.type === 'public') {
  return { accepted: false, date, reason: `Closed for ${holiday.name}.` };
}
return {
  accepted: true, date,
  reason: 'This date meets the business weekday, holiday, and closure policy.'
};

Use the returned holiday.name to explain the rejection. A substitute holiday already carries its published date; leave it on that date rather than shifting it to another Monday.

An unavailable calendar is different from holiday: null. Keep the form available to retry and show that no date was accepted when the request fails.

4. Use the server's decision in the booking flow

The POST handler renders the checked date and its reason:

JavaScript
return `<section class="result">
  <h2>${decision.accepted ? 'Date accepted by policy' : 'Choose another date'}</h2>
  <p><time datetime="${escape(decision.date)}">${escape(decision.date)}</time></p>
  <p>${escape(decision.reason)}</p>
  <p class="note">This checks the date policy. It does not reserve a time slot.</p></section>`;

In your application, put the same decision immediately before the existing booking write. Continue only when accepted is true, and keep your existing slot, capacity, and conflict checks there too. Do not accept an earlier browser result as the final decision.

The standalone app stops at date-policy acceptance and stores no bookings. Editing the input clears an earlier result and cancels an in-flight check. Submitted values and holiday names are escaped before rendering.

See the Holiday reference for calendar coverage and date behavior. For a preparation estimate with a cutoff, build a checkout dispatch date.

Complete example

Use the complete implementation as a reference when adding this feature to your app. It includes the validation and failure handling around the calls above.

View and copy the complete source
Try the complete example on your computer

After completing the setup above, save the source in your application folder and start the app:

Terminal
node holiday-booking-form.node.mjs

Open 127.0.0.1:8000 to use the form. The server keeps your secret key out of the page.

For every field and parameter, see Holiday API reference.

Build something else

All tutorials →