{
  "id": 21322481,
  "title": "Opening messages at local midnight in every time zone",
  "url": "https://urgent.news/2026/11/23/opening-messages-at-local-midnight-in-every-time-zone",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-23T00:48:09.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/wish_tree_app/opening-messages-at-local-midnight-in-every-time-zone-jm4"
  },
  "original_language": "en",
  "account": "To set an event at a user's local midnight, the system needs their IANA time zone alongside the date. In the creation of a record, the system converts the date into a single UTC moment, verifying the offset twice to prevent shifts due to daylight saving changes. The \"is it open yet?\" check becomes a simple integer comparison. The following passage explains why this method was necessary and the challenges encountered. Wish Tree is a platform where friends can attach wishes to a virtual tree, with the wishes opening on specific days such as birthdays, Christmas, or chosen dates. Initially, the opening day was stored as a simple date, which led to mistakes as wishes opened at the first midnight worldwide, causing some recipients to receive early access. To rectify this, the rule was changed to have the tree open at 00:00 on its designated day in the owner's time zone.\n\nWhen a tree is created, the browser transmits the user's time zone, which is then validated and stored with the tree. The code validates the time zone input, confirming it is a string of appropriate length and format, and attempts to create an Intl.DateTimeFormat object using the time zone. The offset from UTC at a particular instant is calculated using the formatted date and time components. This function ensures that the midnight calculation accounts for daylight saving time changes. The final function, zonedMidnight, takes a date and time zone, calculates the local midnight by adjusting the UTC date with the correct offset, and verifies the result by recalculating with the offset at the guessed time. This process ensures accurate midnight calculations, even near daylight saving changes or for zones with unique transition rules.",
  "summary": "How we seal wishes until the right day with Intl, a stored time zone and one integer in D1 To open something at local midnight for a user, store their IANA time zone next to the date. When the record is created, turn that date into a single UTC instant, using Intl.DateTimeFormat and checking the offset twice so daylight saving changes don't shift it. After that, \"is it open yet?\" is one integer…",
  "key_points": [
    "System converts date to UTC moment for local midnight calculation",
    "\"Is it open yet?\" check simplified to integer comparison",
    "Wish Tree opens at 00:00 in user's time zone to prevent early access"
  ],
  "editors_take": "Automating time zone validation and offset recalculation prevents premature access to virtual wishes, ensuring that celebratory events align precisely with each user's local midnight regardless of daylight saving transitions.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}