research/business-days-with-a-holiday-list

Business Days With a Holiday List: Computing the Next Open Day in Node.js Across Time Zones and Daylight Saving

Engineering Note · November 26, 2026 · 9 minute read · Node.js · Dates · Time zones · Testing

To compute “the next day we are open” for a booking form or a “we’ll reply by” message, read today’s date in the business’s time zone with Intl.DateTimeFormat, then step through plain YYYY-MM-DD calendar dates with Date.UTC, skipping weekends and a list of closure days. The version most of us write first, based on new Date() at local midnight plus 24 hours, depends on the server’s time zone and on daylight saving. We checked both every half hour from October 1, 2026 to April 1, 2027. The first version was wrong 13.4 percent of the time with the server on UTC and 84.9 percent with it on Berlin time. Even on a New York server it was wrong for every request across the three days around the end of daylight saving. The fixed version passed an independent check at all 8,736 instants on all four server time zones.

Everything below was run on Linux with Node.js 22.23.5 (ICU 78.3, time zone data 2026e). The server time zone was set per run with the TZ environment variable. The outputs are real.

What is the job?

A hypothetical shop in New York closes on weekends and on these days:

export const TZ = 'America/New_York';
export const CLOSED = new Set(['2026-11-26', '2026-11-27', '2026-12-24', '2026-12-25', '2026-12-31', '2027-01-01']);

Given the current moment, the site needs the next open day after today, in New York. A form uses it to say “we’ll reply by Monday, November 30.” A booking page uses it as the earliest bookable date.

A list of closure days is deliberate. A business’s closures rarely match a public holiday calendar. This one closes the day after Thanksgiving and Christmas Eve, for example. A list is something the owner can read and change, which is why we keep it in code instead of computing holidays with a rule.

What does the first version look like?

This is the version that usually gets written first. It looks reasonable:

export function naiveNextOpenDay(now = new Date()) {
  const d = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  do { d.setTime(d.getTime() + 24 * 60 * 60 * 1000); }
  while (d.getDay() === 0 || d.getDay() === 6 || CLOSED.has(d.toISOString().slice(0, 10)));
  return d.toISOString().slice(0, 10);
}

It has three hidden dependencies:

  1. getFullYear(), getMonth(), getDate() and getDay() use the server’s time zone, not the business’s.
  2. toISOString() gives the date in UTC, which differs from the local date for part of every day.
  3. Adding 24 hours assumes every day is 24 hours long. The day daylight saving ends is 25.

What does the fixed version look like?

Keep calendar dates as strings. Read “today” in the business’s time zone. Do day arithmetic in UTC, where every day is 24 hours, and only on whole dates:

const fmt = new Intl.DateTimeFormat('en-CA', { timeZone: TZ, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', hourCycle: 'h23' });
export function localParts(instant) {
  const p = Object.fromEntries(fmt.formatToParts(instant).map((x) => [x.type, x.value]));
  return { ymd: `${p.year}-${p.month}-${p.day}`, hour: Number(p.hour) };
}
export function addDays(ymd, n) {
  const [y, m, d] = ymd.split('-').map(Number);
  return new Date(Date.UTC(y, m - 1, d + n)).toISOString().slice(0, 10);
}
export function weekday(ymd) {
  const [y, m, d] = ymd.split('-').map(Number);
  return new Date(Date.UTC(y, m - 1, d)).getUTCDay(); // 0 = Sunday
}
export const isOpen = (ymd) => weekday(ymd) !== 0 && weekday(ymd) !== 6 && !CLOSED.has(ymd);
export function nextOpenDay(instant = new Date()) {
  let day = localParts(instant).ymd;
  do day = addDays(day, 1); while (!isOpen(day));
  return day;
}
export function addBusinessDays(ymd, n) {
  let day = ymd;
  while (n > 0) { day = addDays(day, 1); if (isOpen(day)) n--; }
  return day;
}

The en-CA locale is used only because it formats dates as YYYY-MM-DD. Date.UTC handles month and year rollover, so addDays('2026-12-31', 1) is 2027-01-01. The hour field is there for a cutoff rule, such as “requests after 3 PM count from tomorrow.”

localParts depends on Node.js having time zone data. The Node.js documentation says the full ICU data set is provided by default; process.versions.tz shows which time zone release a build carries.

Where do the two versions disagree?

We ran the same five moments, given as UTC instants, with the server on UTC and then on New York time:

server TZ=UTC
Fri Oct 30, 12:00 PM NY  naive=2026-11-02  fixed=2026-11-02
Tue Nov 24, 2:00 PM NY   naive=2026-11-25  fixed=2026-11-25
Tue Nov 24, 8:30 PM NY   naive=2026-11-30  fixed=2026-11-25
Wed Dec 23, 9:00 AM NY   naive=2026-12-28  fixed=2026-12-28
Wed Dec 23, 7:45 PM NY   naive=2026-12-28  fixed=2026-12-28
server TZ=America/New_York
Fri Oct 30, 12:00 PM NY  naive=2026-11-03  fixed=2026-11-02
Tue Nov 24, 2:00 PM NY   naive=2026-11-25  fixed=2026-11-25
Tue Nov 24, 8:30 PM NY   naive=2026-11-25  fixed=2026-11-25
Wed Dec 23, 9:00 AM NY   naive=2026-12-28  fixed=2026-12-28
Wed Dec 23, 7:45 PM NY   naive=2026-12-28  fixed=2026-12-28

Two failures, with two different causes.

Tuesday 8:30 PM on a UTC server. In UTC it is already Wednesday. The first version thinks today is Wednesday, skips Thursday and Friday (both closed) and the weekend, and tells a customer the next open day is Monday, November 30. The right answer is Wednesday, November 25. Servers are often set to UTC, so this is the case to test first.

Friday, October 30 on a New York server. In the time zone data Node.js carries, New York leaves daylight saving time early on Sunday, November 1, 2026, and enters it again on Sunday, March 14, 2027:

2026-11-01T05:30:00Z -> Nov 1, 2026, 1:30 AM EDT
2026-11-01T06:30:00Z -> Nov 1, 2026, 1:30 AM EST
2027-03-14T06:30:00Z -> Mar 14, 2027, 1:30 AM EST
2027-03-14T07:30:00Z -> Mar 14, 2027, 3:30 AM EDT

So November 1 is 25 hours long in New York. Local midnight on Sunday plus 24 hours is 11 PM on Sunday, still Sunday. The loop counts it as a weekend day and moves on to 11 PM Monday, which is 4 AM Tuesday in UTC, and toISOString() returns 2026-11-03. Monday is skipped.

Note that the Wednesday, December 23 rows agree. Both versions say December 28 because the closure list happens to cover the days the bug would have pushed past. A few hand-picked examples miss failures like this, so we swept.

How often is the first version wrong?

We checked every half hour from October 1, 2026 to April 1, 2027 (8,736 instants), with the server in four time zones. For each instant we also checked the fixed answer independently: it must be an open day, after today in New York, with no open day in between.

TZ=UTC: 8736 half-hour instants, naive wrong 1170 (13.4%), fixed failed check 0
TZ=America/New_York: 8736 half-hour instants, naive wrong 146 (1.7%), fixed failed check 0
TZ=America/Los_Angeles: 8736 half-hour instants, naive wrong 878 (10.1%), fixed failed check 0
TZ=Europe/Berlin: 8736 half-hour instants, naive wrong 7414 (84.9%), fixed failed check 0

On UTC, the errors are the evening hours when New York and UTC are on different dates. On Los Angeles time, they are the early-morning hours when New York has moved to the next day and Los Angeles has not. On Berlin time, local midnight is the previous day in UTC, so toISOString() checks the closure list and the answer against the wrong date most of the time.

On a New York server, every error falls in one window:

2026-10-30 48 naive 2026-11-03 fixed 2026-11-02
2026-10-31 48 naive 2026-11-03 fixed 2026-11-02
2026-11-01 50 naive 2026-11-03 fixed 2026-11-02

Every half hour from Friday to Sunday was wrong: 48 + 48 + 50 = 146. November 1 has 50 half hours because it has 25 hours. The start of daylight saving on March 14, 2027 caused no errors in this sweep: a 23-hour day makes “midnight plus 24 hours” land at 1 AM the next day, which is still the right date.

The fixed version gave the same answers on all four server time zones, which is the property that matters. It does not depend on where the code runs.

Does “two business days” work too?

A reply promise like “within two business days” uses addBusinessDays. Starting from the date the message arrived, in New York:

2026-11-24 + 2 business days = 2026-11-30
2026-11-25 + 2 business days = 2026-12-01
2026-12-22 + 2 business days = 2026-12-28
2026-12-23 + 2 business days = 2026-12-29
2026-12-29 + 2 business days = 2027-01-04

A message on Tuesday, November 24 counts Wednesday the 25th, then skips Thanksgiving, the Friday after and the weekend, and lands on Monday the 30th. A message on December 29 counts the 30th, skips the 31st, January 1 and the weekend, and lands on January 4.

What should go where in a real app?

  • Store instants in UTC (timestamps of when things happened) and store calendar days as YYYY-MM-DD strings (closure days, booking dates). They are different kinds of value.
  • Name the business’s time zone once, in configuration, and pass it every time you turn an instant into a local date or hour.
  • Keep the closure list where the owner can change it, such as a settings page or a small file, with the year in every date.
  • Test across the daylight saving change and with the server set to UTC. The half-hour sweep over six months took about 0.15 seconds here.
  • Show the date to the customer in words (“Monday, November 30”), formatted with the same time zone.

The same approach is behind the 9:30 AM New York publish time for this research section, described in Scheduling Posts on a Static Site at a Local Time of Day.

Limitations

  • We tested one business time zone, America/New_York, against four server time zones. A business in a zone that changes daylight saving at midnight, or one that has changed its rules recently, needs its own sweep.
  • The sweep covers October 2026 to March 2027, one end and one start of daylight saving. The results depend on the time zone data in the Node.js build; ours was 2026e.
  • The closure list is hypothetical. We did not test opening hours within a day, such as a 3 PM cutoff, beyond showing that localParts returns the local hour.
  • We tested Node.js only. Browsers implement the same Intl API, but a date computed in a customer’s browser uses the customer’s device clock and settings, so we compute it on the server.
  • Temporal, the newer JavaScript date API, would make this simpler with plain-date types. typeof Temporal is undefined in our Node.js 22 build, so we did not test it.

Sources

Frequently asked questions

How do I calculate the next business day in JavaScript?

Read today's date in the business's time zone with Intl.DateTimeFormat and a timeZone option, then add days to that calendar date with Date.UTC and check each one against weekends and a closure list. Keep the dates as YYYY-MM-DD strings. In our test this was correct for every half hour across six months on four different server time zones.

Why does my business-day calculation give the wrong day in the evening?

Usually because the server runs on UTC. At 8:30 PM in New York it is already the next day in UTC, so code that reads today's date from the server's clock skips a day. In our run, a Tuesday 8:30 PM request was told the next open day was the following Monday instead of Wednesday.

Why does adding 24 hours to a date break around daylight saving?

Because the day daylight saving ends is 25 hours long. Adding 24 hours to local midnight on that day lands at 11 PM the same day, and every later step stays an hour behind. In our test on a New York server, this made the function skip Monday, November 2, 2026 for three days of requests.

Should I compute holidays with a formula or keep a list?

For a small business, keep a list of the days you are actually closed and update it each year. Closures rarely match a public holiday calendar exactly: many businesses close the day after a holiday, or around the new year. A list is easy to read, easy to test and easy for the owner to change.

What time zone should a booking server use?

Whatever it runs on, as long as the code never depends on it. Pass the business's time zone, such as America/New_York, explicitly every time you need a local date or hour. Our fixed function gave the same answers with the server set to UTC, New York, Los Angeles and Berlin.

More from Research

← All research