Preloader
Others
  • Estimated reading time: 11 Minutes

How to Respect SMS Quiet Hours in Node.js: Time Zones, State Rules and a Send Queue

How to Respect SMS Quiet Hours in Node.js: Time Zones, State Rules and a Send Queue

Most SMS bugs are loud. A message fails, an API returns a 400, a webhook never fires. Quiet hours bugs are silent. The text goes out, the provider says delivered, and nobody notices that it landed at 6:12 a.m. on a phone in Los Angeles because the job ran at 9:12 a.m. on a server in New York.

For marketing texts in the United States, that timing is a legal rule, not a nicety. This tutorial builds a small, dependency-free Node.js module that decides, for each contact, whether a text can go out now or when the next allowed slot opens. It covers the recipient's time zone, stricter state windows, Sunday rules, holidays and per-contact daily caps.

The code uses only built-in APIs (Intl.DateTimeFormat and Date), so it runs on any current Node.js version without extra packages.

The rules your code has to encode

Before writing code, it helps to list the rules as data. The baseline is federal: the FCC's TCPA rules (47 CFR 64.1200) allow telephone solicitations only between 8 a.m. and 9 p.m. in the called party's local time, and the FCC applies that rule to texts. (A 2026 Seventh Circuit ruling limits private lawsuits over texts in Illinois, Indiana and Wisconsin, but the FCC rule itself still applies.)

Several states go further. A summary that matters for a scheduler:

  • Earlier end times. Florida, Oklahoma, Washington, Maryland, Massachusetts, Oregon, Alabama, Louisiana, Mississippi and Connecticut stop at 8 p.m. Pennsylvania stops at 7 p.m. Rhode Island stops at 6 p.m. on weekdays.
  • Later start times. Texas, Pennsylvania, Connecticut and Rhode Island start at 9 a.m.
  • Day rules. Alabama, Louisiana, Mississippi, Utah, Rhode Island and Pennsylvania block Sundays. Texas allows Sunday texts only from noon. Rhode Island has a shorter Saturday window.
  • Daily caps. Florida, Oklahoma and Maryland allow at most three texts on the same subject to one person in 24 hours. Oregon has a similar cap, which does not apply when you have an established business relationship with the person.

These rules change. Pennsylvania's window and Oregon's cap both changed in the last year, so treat the table as configuration you review, not constants you forget. A maintained reference such as this state-by-state SMS quiet hours table is a good source to check it against. None of this is legal advice; confirm the states you text most with counsel.

Chart of SMS send windows by state, from the federal 8 a.m. to 9 p.m. window down to Rhode Island's 9 a.m. to 6 p.m.

Send windows in the recipient's local time. The strictest rule that applies to a contact wins.

Step 1: Store the rules as data

Keeping rules in one object makes them easy to review and test. Hours use a 24-hour clock, days use JavaScript's numbering (0 is Sunday), and null means no sending that day.

// quietHours.js
const FEDERAL = { start: 8, end: 21 };

const STATE_RULES = {
  FL: { start: 8, end: 20, dailyCap: 3 },
  OK: { start: 8, end: 20, dailyCap: 3 },
  MD: { start: 8, end: 20, dailyCap: 3 },
  OR: { start: 8, end: 20, dailyCap: 3 },
  WA: { start: 8, end: 20 },
  MA: { start: 8, end: 20 },
  CT: { start: 9, end: 20 },
  TX: { start: 9, end: 21, days: { 0: { start: 12, end: 21 } } },
  PA: { start: 9, end: 19, days: { 0: null } },
  AL: { start: 8, end: 20, days: { 0: null } },
  LA: { start: 8, end: 20, days: { 0: null } },
  MS: { start: 8, end: 20, days: { 0: null } },
  UT: { start: 8, end: 21, days: { 0: null } },
  RI: { start: 9, end: 18, days: { 0: null, 6: { start: 10, end: 17 } } },
};

Any state that is not listed falls back to the federal window.

Step 2: Map a phone number to a state and time zone

The rules run on the recipient's clock, so every contact needs an IANA time zone. In the US the usual source is the area code. The sample below holds a few entries; in production, load a full area code table and refresh it, since new codes are added every year.

// A tiny sample. In production, load a full area code table.
const AREA_CODES = {
  "212": { state: "NY", tz: "America/New_York" },
  "215": { state: "PA", tz: "America/New_York" },
  "305": { state: "FL", tz: "America/New_York" },
  "401": { state: "RI", tz: "America/New_York" },
  "512": { state: "TX", tz: "America/Chicago" },
  "206": { state: "WA", tz: "America/Los_Angeles" },
  "213": { state: "CA", tz: "America/Los_Angeles" },
  "602": { state: "AZ", tz: "America/Phoenix" },
};

// "+1 (305) 555-0101" and "3055550101" become the same key.
function normalize(phone) {
  return phone.replace(/\D/g, "").replace(/^1(?=\d{10}$)/, "");
}

function lookup(phone) {
  return AREA_CODES[normalize(phone).slice(0, 3)] || null;
}

Two cautions. First, people keep their numbers when they move, so an area code is a hint, not proof. If you also have a mailing address, apply both states. Florida, Oklahoma and Maryland presume that a number with one of their area codes belongs to a resident, so the area code state should never be dropped in favor of the address. Second, a few states span two time zones. When an area code straddles a zone line, check the window in both zones and send only when both are open. Picking just the western zone avoids early texts but allows late ones: 8:30 p.m. Central is already 9:30 p.m. Eastern.

Step 3: Read the recipient's local clock

Intl.DateTimeFormat with formatToParts converts any instant into a weekday, date and time in a given zone, daylight saving included. That is all the scheduler needs.

function localClock(date, tz) {
  const parts = new Intl.DateTimeFormat("en-US", {
    timeZone: tz, hourCycle: "h23", weekday: "short",
    year: "numeric", month: "2-digit", day: "2-digit",
    hour: "2-digit", minute: "2-digit",
  }).formatToParts(date);
  const get = (type) => parts.find((p) => p.type === type).value;
  const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  return {
    day: days.indexOf(get("weekday")),
    ymd: `${get("month")}-${get("day")}`,
    minutes: Number(get("hour")) * 60 + Number(get("minute")),
  };
}

Use hourCycle: "h23" rather than hour12: false. Some runtimes print midnight as 24 with hour12: false, which breaks the minute math.

Step 4: Combine the rules into one window

A contact can fall under more than one state. The safe answer is the intersection: the latest start and the earliest end. If any state blocks that day, the whole day is blocked.

function windowFor(state, day) {
  const rule = STATE_RULES[state];
  if (!rule) return FEDERAL;
  if (rule.days && day in rule.days) return rule.days[day];
  return { start: rule.start, end: rule.end };
}

function combinedWindow(states, day) {
  let win = { ...FEDERAL };
  for (const s of states) {
    const w = windowFor(s, day);
    if (w === null) return null;
    win = { start: Math.max(win.start, w.start), end: Math.min(win.end, w.end) };
  }
  return win.start < win.end ? win : null;
}

function dailyCap(states) {
  const caps = states.map((s) => STATE_RULES[s]?.dailyCap).filter(Boolean);
  return caps.length ? Math.min(...caps) : Infinity;
}

Step 5: Decide now or later

The scheduler checks three things per contact: is the area code known, is the contact under its daily cap, and is the window open right now. If not, it walks forward in five-minute steps until it finds the next open slot. Holidays are passed in as a set of local dates. This sample applies one list to every contact; in production, key the list by state, since Pennsylvania, Alabama, Louisiana, Utah and Rhode Island block holidays and most states do not. The cap also counts every text to a contact, not only texts on the same subject, which is the conservative reading.

// scheduler.js
const { normalize, lookup, localClock, combinedWindow, dailyCap } = require("./quietHours");

const DAY_MS = 24 * 60 * 60 * 1000;
const STEP_MS = 5 * 60 * 1000;

function contactRules(contact) {
  const fromPhone = lookup(contact.phone);
  if (!fromPhone) return null; // unknown area code: hold for review
  const states = new Set([fromPhone.state]);
  if (contact.addressState) states.add(contact.addressState);
  return { tz: fromPhone.tz, states: [...states] };
}

function isOpen(rules, date, holidays = new Set()) {
  const clock = localClock(date, rules.tz);
  if (holidays.has(clock.ymd)) return false;
  const win = combinedWindow(rules.states, clock.day);
  if (!win) return false;
  // The last send must start before the window closes.
  return clock.minutes >= win.start * 60 && clock.minutes < win.end * 60;
}

// Walk forward in 5-minute steps until the window opens (at most 8 days).
function nextOpenSlot(rules, from, holidays) {
  let t = new Date(Math.ceil(from.getTime() / STEP_MS) * STEP_MS);
  const limit = from.getTime() + 8 * DAY_MS;
  while (t.getTime() <= limit) {
    if (isOpen(rules, t, holidays)) return t;
    t = new Date(t.getTime() + STEP_MS);
  }
  return null;
}

// sentLog: Map of normalized phone -> array of send timestamps (ms).
function recentSends(contact, now, sentLog) {
  return (sentLog.get(normalize(contact.phone)) || []).filter((ts) => now - ts < DAY_MS);
}

function plan(contacts, now = new Date(), { holidays = new Set(), sentLog = new Map() } = {}) {
  const sendNow = [], later = [], review = [];
  for (const c of contacts) {
    const rules = contactRules(c);
    if (!rules) { review.push({ ...c, reason: "unknown area code" }); continue; }
    const recent = recentSends(c, now.getTime(), sentLog);
    if (recent.length >= dailyCap(rules.states)) {
      const oldest = Math.min(...recent);
      const slot = nextOpenSlot(rules, new Date(oldest + DAY_MS), holidays);
      later.push({ ...c, at: slot, reason: "daily cap" });
      continue;
    }
    if (isOpen(rules, now, holidays)) { sendNow.push(c); continue; }
    const at = nextOpenSlot(rules, now, holidays);
    if (at) later.push({ ...c, at, reason: "quiet hours" });
    else review.push({ ...c, reason: "no open slot in 8 days" });
  }
  return { sendNow, later, review };
}

module.exports = { plan, nextOpenSlot, contactRules, isOpen };

The sent log is keyed by the normalized number, so +1 305 555 0101 and (305) 555-0101 count as the same person. Unknown area codes go to a review list instead of being guessed. Sending to a number you cannot place is how a "safe" queue ends up texting someone at 6 a.m.

Step 6: Run it

Here is a test run for Sunday, 1 February 2026, at 11:30 a.m. in New York. The Florida contact has already received three texts in the last 24 hours.

const { plan } = require("./scheduler");

const contacts = [
  { name: "Ana", phone: "+1 305 555 0101" },           // Florida
  { name: "Ben", phone: "(213) 555-0102" },            // California
  { name: "Cara", phone: "512-555-0103" },             // Texas
  { name: "Dev", phone: "215 555 0104" },              // Pennsylvania
  { name: "Eli", phone: "212 555 0105", addressState: "FL" }, // NY number, lives in FL
  { name: "Fay", phone: "808 555 0106" },              // not in the sample table
];

const now = new Date("2026-02-01T16:30:00Z");
const sentLog = new Map([["3055550101", [now - 3600e3, now - 7200e3, now - 10800e3]]]);
console.log(plan(contacts, now, { sentLog }));

The output, with times shown on a New York clock:

  • send now: Ben, Eli
  • later: Ana daily cap Mon 8:30 AM
  • later: Cara quiet hours Sun 1:00 PM (noon in Texas)
  • later: Dev quiet hours Mon 9:00 AM (Pennsylvania blocks Sunday)
  • review: Fay unknown area code

Run the same list at 9:30 p.m. Eastern on Saturday and the picture flips. Ben (6:30 p.m. in Los Angeles) and Cara (8:30 p.m. in Austin) can still receive a text, while Ana and Eli wait until 8 a.m. Sunday because Florida closes at 8 p.m.

Flow of the Node.js SMS scheduler: look up area code, check daily cap, check local window, then send now, schedule later or hold for review

Every contact ends in one of three lists: send now, later at a computed time, or human review.

Step 7: Wire it into a real queue

The plan function is pure, which makes it easy to test and easy to plug into whatever you already run:

  • With a job queue (BullMQ, Agenda, a database table): push sendNow to the sender and create delayed jobs for later using at - Date.now() as the delay. Contacts with no open slot in the next eight days are already in review.
  • Re-check at send time. A job delayed by hours can run late after a restart. Call isOpen again right before the API call and reschedule if the window has closed.
  • Record every send in sentLog (or its database equivalent) at the moment the provider accepts the message, not when you queue it, so the daily cap counts what actually went out.
  • Pace inside the window. If a list is large, spread sends across the open window instead of firing them all at the opening minute. Carriers throttle bursts, and a list that starts at 9:00 sharp can still be draining at 9 p.m.

Testing tips

Time zone code fails at the edges, so test the edges:

  • The minute before and after each window boundary (7:59 and 8:00, 19:59 and 20:00).
  • The daylight saving switch in March and November, when a local hour repeats or disappears.
  • Arizona, which does not observe daylight saving, so its offset from California changes twice a year.
  • A contact whose area code state and address state have different rules.
  • A cap that clears in the middle of a closed window, which should roll to the next opening, not the moment the cap clears.

Freeze the clock by passing now into plan, as the example does, rather than mocking Date globally.

Build it or buy it

The two files above come to about 145 lines and cover the core logic. What it leaves out is the work around it: keeping the area code and state tables current, holiday calendars per state, consent records, STOP handling and throughput limits per number. If you would rather not own that, most texting platforms, Textivo among them, already hold sends outside each recipient's local window, so check what yours does before you build.

If you do build it yourself, keep the rules as data, review them on a schedule, and let the strictest rule win. Your queue will send fewer texts at the wrong time, and none at 6 a.m.

FAQ

Do quiet hours apply to transactional texts like order updates?

The federal 8 a.m. to 9 p.m. window covers telephone solicitations, which means marketing. Many teams still apply it to every non-urgent text, since a 6 a.m. shipping update annoys people just as much. Urgent alerts such as fraud or security codes usually go out immediately.

Which time zone counts, mine or the recipient's?

The recipient's. A send scheduled for 9 a.m. in New York reaches phones in California at 6 a.m.

Can I rely on the area code alone?

It is the common method, but numbers move with people. Use a mailing address or ZIP code when you have one and apply both sets of rules.

What should happen to a text that misses its window?

Hold it for the next open slot in the recipient's time zone, then check the window again right before sending.

Related articles
Parental Control App for iPhone: 7 Best Solutions in 2027
3 Dec, 2026
  • Estimated reading time: 3 Minutes
Digital Packaging Design: From 3D Mockups to Production
3 Dec, 2026
  • Estimated reading time: 6 Minutes
Top Browser Based Social Media Tools
3 Dec, 2026
  • Estimated reading time: 3 Minutes
Best AI Search Visibility Agencies for Universities and Colleges
3 Dec, 2026
  • Estimated reading time: 8 Minutes
Weekly trending
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.