Dev.to WebDev πŸ›  Dev πŸ‘ 2 πŸ“– 1 min read

When should a calendar door unlock? Store the time zone with the calendar

A calendar door labelled December 4 should open on December 4 for the person who made the calendar. UTC midnight would open it on the evening of December 3 in Los Angeles. Using the visitor's browser time zone creates a

A calendar door labelled December 4 should open on December 4 for the person who made the calendar. UTC midnight would open it on the evening of December 3 in Los Angeles. Using the visitor's browser time zone creates a different problem: two people can see different states for the same door.

Treat the door date as a civil date, and store the calendar's IANA time zone when the host creates it. The examples below use plain JavaScript; they aren't a drop-in authorization implementation.

function dateInZone(instant, timeZone) {
  const formatter = new Intl.DateTimeFormat('en-US', {
    timeZone,
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
  });
  const parts = Object.fromEntries(
    formatter.formatToParts(instant).map(({ type, value }) => [type, value]),
  );
  return [parts.year, parts.month, parts.day].join('-');
}

const zone = 'America/Los_Angeles';
const doorDate = '2026-12-04';
console.assert(dateInZone(new Date('2026-12-04T07:59:00Z'), zone) < doorDate);
console.assert(dateInZone(new Date('2026-12-04T08:00:00Z'), zone) === doorDate);

A fixed-width date string sorts in calendar order. For a door that stays open after its date, use today >= doorDate. Passing the time zone to Intl also keeps you from hard-coding an offset that breaks when daylight saving time changes.

For a private letter, evaluate that comparison with the server's current clock before releasing the letter. The UI may use the same calculation for a countdown. Keep authorization tied to the recipient even after the date arrives: opening the calendar door and being able to read the letter are separate checks.

I used Note Doors as the example. Its shareable invite lets friends contribute, while the host opens dates in the calendar's saved time zone.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.