research/late-cancel-fee-across-time-zones
A Late-Cancel Window for a Booking: Deciding Whether a Fee Applies Across Time Zones and Daylight Saving, Tested in Node.js
Engineering Note · December 4, 2026 · 9 minute read · Node.js · Dates · Time zones · Testing
To decide whether a cancellation is free, late or a no-show, store the appointment as an instant, subtract the window in elapsed milliseconds, and compare. The version that usually gets written first keeps the appointment as a local wall time such as 2026-12-07T09:00 and parses it with new Date() on the server, which quietly uses the server’s time zone. We checked both against an independent reference every 15 minutes from 48 hours before to an hour after every hourly slot, 8 AM to 5 PM, for every day from October 1, 2026 to March 31, 2027. The first version charged a fee it should not have in 19.2 percent of checks on a UTC server and 23.9 percent on a Berlin server. On a Los Angeles server it went the other way and missed 8.6 percent of fees. The fixed version passed all 358,540 checks on every server time zone. The two daylight saving days also showed that “24 hours before” is a policy decision, not only a code one.
Everything below was run on Linux with Node.js 22.23.5 (ICU 78.3, time zone data 2026e). The server’s time zone was set per run with the TZ environment variable. The outputs shown are real.
What is the policy?
A hypothetical salon in New York takes bookings online with this rule:
- Cancel 24 hours or more before the appointment: free.
- Cancel less than 24 hours before: late-cancel fee.
- Cancel at or after the start time, or don’t come: no-show fee.
The code has to answer one question for a cancellation: free, late or no-show. The deposit itself is a separate problem.
What does the first version look like?
export const FREE_UNTIL_HOURS = 24;
export function naiveFee(apptLocal, cancelAt) {
const appt = new Date(apptLocal); // parsed in the SERVER's zone
const deadline = new Date(appt);
deadline.setHours(deadline.getHours() - FREE_UNTIL_HOURS); // server-zone wall-clock math
if (cancelAt >= appt) return 'no-show';
return cancelAt > deadline ? 'late' : 'free';
}
It reads well and passes a quick test on a laptop in New York. It has two hidden dependencies:
new Date('2026-12-07T09:00')has no zone, so JavaScript reads it as local time on the machine running the code. On a server set to UTC, that is 9:00 AM UTC, which is 4:00 AM in New York.setHours(getHours() - 24)subtracts 24 hours of clock time in the server’s zone, which is not always 24 elapsed hours.
Here is one cancellation, Sunday at 8:30 AM New York time, for a Monday 9:00 AM appointment, on two servers:
$ TZ=America/New_York node example.mjs
TZ=America/New_York naive: free fixed: free
$ TZ=UTC node example.mjs
TZ=UTC naive: late fixed: free
Same customer, same click, 24.5 hours’ notice. The UTC server charges a late fee.
What does the fixed version look like?
Store the appointment as an instant. Convert the business’s wall time to an instant once, when the slot is created, with the business’s time zone named explicitly. Then the fee decision is plain arithmetic:
export function fee(apptInstant, cancelAt) {
const deadline = apptInstant.getTime() - FREE_UNTIL_HOURS * 36e5;
if (cancelAt.getTime() >= apptInstant.getTime()) return 'no-show';
return cancelAt.getTime() > deadline ? 'late' : 'free';
}
Node.js 22 has no built-in Temporal API, so we converted wall times with Intl.DateTimeFormat. The function finds the zone’s offset near the wall time, tries it, and keeps the candidates that round-trip:
export function zonedToInstant(ymdhm, tz = 'America/New_York') {
const [d, t] = ymdhm.split('T');
const [y, mo, da] = d.split('-').map(Number);
const [h, mi] = t.split(':').map(Number);
const wall = Date.UTC(y, mo - 1, da, h, mi);
const candidates = new Set();
for (const probe of [wall - 36e5 * 14, wall + 36e5 * 14]) {
const off = offsetMinutes(tz, probe); // via Intl formatToParts
const inst = wall - off * 60000;
if (offsetMinutes(tz, inst) === off) candidates.add(inst);
}
if (!candidates.size) throw new RangeError(`${ymdhm} does not exist in ${tz}`);
return new Date(Math.min(...candidates));
}
offsetMinutes formats the instant in the zone with formatToParts, rebuilds those parts as if they were UTC, and returns the difference. Two rules are deliberate. A wall time that happens twice, such as 1:30 AM on the morning daylight saving ends, resolves to the earlier instant. A wall time that does not exist, such as 2:30 AM on the morning it starts, throws, so a booking page never offers that slot:
2026-11-01T05:30:00.000Z (1:30 AM happens twice; earlier one)
2027-03-14T02:30 does not exist in America/New_York
How did we test it?
The reference had to be independent of both versions. We wrote New York’s offsets out by hand for the test range: UTC−4 until 06:00 UTC on November 1, 2026, then UTC−5 until 07:00 UTC on March 14, 2027, then UTC−4 again. From those, the reference computes each appointment instant and the correct answer for each cancellation time.
The sweep covered every day from October 1, 2026 to March 31, 2027, ten hourly slots per day (8 AM to 5 PM New York), and a cancellation every 15 minutes from 48 hours before each slot to one hour after. That is 182 days × 10 slots × 197 cancellation times = 358,540 checks. We ran it with the server set to four zones:
$ for tz in UTC America/New_York America/Los_Angeles Europe/Berlin; do TZ=$tz node sweep.mjs; done
TZ=UTC: 358540 checks, naive wrong 68880 (19.2%), fixed wrong 0
TZ=America/New_York: 358540 checks, naive wrong 80 (0.0%), fixed wrong 0
TZ=America/Los_Angeles: 358540 checks, naive wrong 30940 (8.6%), fixed wrong 0
TZ=Europe/Berlin: 358540 checks, naive wrong 85680 (23.9%), fixed wrong 0
Which way the mistakes go matters as much as how many there are. We counted them separately:
TZ=UTC: charged when they should not be 68880, not charged when they should be 0, days affected 182
TZ=America/New_York: charged when they should not be 40, not charged when they should be 40, days affected 2 2026-11-01,2027-03-14
TZ=America/Los_Angeles: charged when they should not be 0, not charged when they should be 30940, days affected 182
TZ=Europe/Berlin: charged when they should not be 85680, not charged when they should be 0, days affected 182
A server east of the business (UTC, Berlin) moves every deadline earlier, so it charges people who cancelled in time. That is the costly direction: a fee a customer can show they should not have paid, and a chargeback or a review to go with it. A server west of the business (Los Angeles) moves deadlines later, so the business silently loses fees. On a New York server the first version was wrong only on the two daylight saving days, 40 times each way.
What does daylight saving do to “24 hours before”?
Those 80 mismatches on the New York server are not really a bug in the code. They are a question the policy never answered. On a day when the clocks change, 24 elapsed hours and “the same clock time the day before” are different moments:
2026-11-01T10:00 | 24 hours before: Sat, Oct 31, 11:00 AM EDT
2027-03-14T10:00 | 24 hours before: Sat, Mar 13, 9:00 AM EST
2026-11-02T10:00 | 24 hours before: Sun, Nov 1, 10:00 AM EST
November 1, 2026 is 25 hours long in New York, so 24 elapsed hours before 10:00 AM that Sunday is 11:00 AM Saturday. March 14, 2027 is 23 hours long, so it is 9:00 AM. The day after, everything lines up again.
We wrote the second reading as its own function, feeSameClockTime, which takes the previous calendar day at the same wall time as the deadline. Then we cancelled at a time between the two deadlines:
cancel Sat, Oct 31, 10:30 AM EDT -> elapsed rule: free | same-clock rule: late
cancel Sat, Mar 13, 9:30 AM EST -> elapsed rule: late | same-clock rule: free
Both are defensible. “24 hours” in a policy reads as elapsed time. “The day before by this time” reads as clock time, and it is what a customer looking at a clock will assume. Pick one, use the same words in the policy, the confirmation email and the code, and test the two change days on purpose. The first version above was neither: it used clock time in whatever zone the server happened to be in.
Where is the boundary?
The code also has to say what happens at the exact deadline. We made the deadline itself free, so a customer who cancels at the very time printed in their confirmation is never charged:
at deadline: free | one ms later: late | at start: no-show
The same deadline is one instant everywhere. Only its display changes, which is why the confirmation should name the zone:
America/New_York free until Sun, Dec 6, 9:00 AM EST
America/Los_Angeles free until Sun, Dec 6, 6:00 AM PST
Europe/London free until Sun, Dec 6, 2:00 PM GMT
That output came from the same script run with the server set to UTC and to Berlin. The answers did not change.
What should go in the database?
- The appointment as an instant (UTC timestamp), plus the business’s time zone name as a separate column, so the original wall time can be shown again.
- The policy that applied when it was booked: the window in hours and which rule it uses. If the policy changes, existing bookings keep the terms the customer agreed to.
- The cancellation instant, recorded by the server, not sent by the browser.
If cancellations come in through emailed links or a form that can be submitted twice, pair this with idempotency keys so a retry cannot record two cancellations or charge twice.
Limitations
- The reference offsets were written by hand for New York between October 2026 and March 2027. The fixed function relies on Node’s time zone data (2026e here) for other zones and other years.
- We tested hourly slots from 8 AM to 5 PM. Slots during the night of a daylight saving change, where wall times are repeated or skipped, were tested only through the two
zonedToInstantexamples above. - We tested the decision, not the charge. Whether a business may charge a late-cancel or no-show fee, and what it must disclose first, depends on its payment processor’s terms and on local law, neither of which this note covers.
- A server in New York hides the time zone bug, so a test suite run on a developer’s laptop in the same zone as the business will not catch it. Run the tests with
TZ=UTCas well.
Related reading
- Business Days With a Holiday List: Computing the Next Open Day in Node.js Across Time Zones and Daylight Saving
- Idempotency Keys for a Booking Form: Stopping Double Clicks and Retries From Creating Two Bookings
- Money in Integer Cents: Where Floating Point Drifts on Deposits, Discounts and Tax, Tested in Node.js
Frequently asked questions
How do I check if a cancellation is within 24 hours of an appointment in JavaScript?
Store the appointment as an instant (a UTC timestamp), subtract 24 × 60 × 60 × 1000 milliseconds to get the deadline, and compare the cancellation time against it. Do not parse a local wall time like 2026-12-07T09:00 with new Date on the server, because that uses the server's time zone. In our test this approach agreed with an independent reference on all 358,540 checks on four server time zones.
Why does my late-cancel fee charge customers who cancelled in time?
Usually because the appointment's local time was parsed in the server's time zone. On a UTC server, a 9:00 AM New York appointment becomes 9:00 AM UTC, which is 4:00 AM in New York, so the deadline moves five hours earlier. In our test that wrongly charged a late fee in 19.2 percent of checks.
Does daylight saving change a 24-hour cancellation deadline?
Only for appointments within a day after a change. For a 10:00 AM appointment on Sunday, November 1, 2026 in New York, 24 elapsed hours earlier is 11:00 AM Saturday, not 10:00 AM, because that Sunday is 25 hours long. Decide whether your policy means 24 elapsed hours or the same clock time the day before, and write that into the code and the policy text.
Is cancelling exactly at the deadline free or late?
Whatever your policy says, but the code has to pick one. We made a cancellation at exactly the deadline free and one millisecond later late, so a customer who cancels at the time the confirmation email shows is never charged.
What time zone should a cancellation deadline be shown in?
Show it in the business's time zone with the zone name, such as 9:00 AM EST, and consider adding the customer's own zone when it differs. The deadline is one instant, so the fee decision does not change, only how it is displayed.