◉ANTIGRAVITY LABJP
Articles/App Development
▣ App Development/2026-11-20Intermediate

Correct on My Machine, Nine Hours Off in Production: Tracking Down Offset-less Date Strings

Why sitemap lastmod and JSON-LD datePublished drift exactly nine hours ahead only in production, how JavaScript parses date-only and date-time strings differently, and a detection script plus TZ-pinned tests you can run today.

Cloudflare Workers9Next.js9Time zonessitemapJavaScript Date

One morning I was scrolling through the sitemap of a page I had just updated, reading the lastmod column from the top. The newest entry pointed to a time later than the clock on my wall. When I rebuilt the same site on my iMac, every timestamp looked right.

Only the production output, served from Cloudflare Workers, was wrong. And the gap was exactly nine hours — the difference between Japan Standard Time and UTC.

The short version: this wasn't a Workers bug. I was handing date strings without a UTC offset straight to new Date(). As an indie developer running a Next.js site, I'd gotten into the habit of writing frontmatter like date: "2026-03-22T10:00", and it took a while to see what that habit was costing me.

First, check whether the gap is exactly nine hours

When a timestamp looks off, measure the size of the error before anything else. A clean nine-hour gap (or whatever your local offset is) almost always means a time zone interpretation problem. A gap of a few minutes points somewhere else, like caching or delayed deploys.

These are the places where it showed up for me:

OutputWhat you seeWhy it hides
sitemap.xml lastmodUpdate times in the future, or dates off by one dayNobody reads sitemaps by eye
JSON-LD datePublished / dateModifiedPublish time nine hours aheadOnly visible in rich result testing
OGP article:published_timeWrong time on share cardsMany platforms don't display it
RSS pubDateFeed readers sort items oddlyYou hear about it from subscribers

If you only look at the dates rendered on the page, you'll probably miss all of this. Display dates usually show just the day, and a post published in the afternoon stays on the same calendar day even when it's nine hours off.

Why the same string becomes two different moments

Reproducing it locally takes one loop. Switch the runtime time zone with TZ and parse the same three strings:

for tz in UTC Asia/Tokyo; do
  TZ=$tz node -e 'for (const s of ["2026-03-22T10:00","2026-03-22","2026-03-22T10:00:00+09:00"]) console.log(process.env.TZ.padEnd(10), s.padEnd(26), new Date(s).toISOString())'
done

Here's what Node.js v22 printed:

UTC        2026-03-22T10:00           2026-03-22T10:00:00.000Z
UTC        2026-03-22                 2026-03-22T00:00:00.000Z
UTC        2026-03-22T10:00:00+09:00  2026-03-22T01:00:00.000Z
Asia/Tokyo 2026-03-22T10:00           2026-03-22T01:00:00.000Z
Asia/Tokyo 2026-03-22                 2026-03-22T00:00:00.000Z
Asia/Tokyo 2026-03-22T10:00:00+09:00  2026-03-22T01:00:00.000Z

Compare the first and fourth lines. A date-time string without an offset is read in whatever time zone the runtime happens to be in. My Mac is on JST, so it came out right; anything running on UTC lands nine hours later. Cloudflare Workers runs on UTC, and so do GitHub-hosted Actions runners by default.

The second and fifth lines surprised me more. The date-only string "2026-03-22" was read as midnight UTC in both environments — which is 9 a.m. in Japan. The JavaScript spec treats date-only forms as UTC and date-time forms as local time, so "no offset" actually behaves two different ways.

I had assumed that if things looked right locally, the date-only values were fine too. They weren't. Those were nine hours late on my machine and in production.

The fix: add the offset while it's still a string

I settled on a single rule: before any frontmatter value becomes a Date, normalize it into a string that carries the JST offset.

// to-iso-jst.mjs
const OFFSET = /([Zz]|[+-]\d{2}:\d{2})$/;
 
export function toIsoJst(value) {
  if (!value) return "";
  if (OFFSET.test(value)) return value;
  if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return `${value}T00:00:00+09:00`;
  if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(value)) return `${value}:00+09:00`;
  if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.test(value)) return `${value}+09:00`;
  throw new Error(`Unexpected date format: ${value}`);
}

At call sites, new Date(article.date) becomes new Date(toIsoJst(article.date)). I routed every place that emits a timestamp to the outside world — sitemap, JSON-LD, OGP, RSS — through it.

The strict patterns are deliberate. Something like 2026/03/22 shouldn't slip through quietly. On my production site the function returns unknown formats unchanged, but for this version I chose to throw: a failed build is far easier to live with than wrong timestamps shipping unnoticed for weeks.

You could also patch the display with toLocaleString and a timeZone option. That fixes what humans see, but not the machine-readable lastmod or datePublished. Attach the offset while it's a string; turn it into a Date only after that. That ordering is the one thing I hold to now.

Catching it even when your laptop hides the problem

Once it was fixed, the next problem was that I couldn't see regressions as long as my machine stayed on JST. So I wrote a small script that lists every offset-less value and computes, without relying on the runtime's time zone, what a UTC environment would make of it.

// check-dates.mjs — usage: node check-dates.mjs content
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { toIsoJst } from "./to-iso-jst.mjs";
 
const OFFSET = /([Zz]|[+-]\d{2}:\d{2})$/;
 
// Build the "UTC runtime" reading by hand so the result doesn't depend on TZ
function asIfUtcRuntime(value) {
  return /^\d{4}-\d{2}-\d{2}$/.test(value)
    ? new Date(`${value}T00:00:00Z`)
    : new Date(`${value.length === 16 ? value + ":00" : value}Z`);
}
 
function walk(dir) {
  return readdirSync(dir, { withFileTypes: true }).flatMap((e) =>
    e.isDirectory() ? walk(join(dir, e.name)) : e.name.endsWith(".mdx") ? [join(dir, e.name)] : []
  );
}
 
let flagged = 0;
for (const file of walk(process.argv[2] ?? "content")) {
  const fm = readFileSync(file, "utf8").split("---")[1] ?? "";
  for (const key of ["date", "updated"]) {
    const m = fm.match(new RegExp(`^${key}:\\s*"([^"]+)"`, "m"));
    if (!m || OFFSET.test(m[1])) continue;
    const wrong = asIfUtcRuntime(m[1]);
    const right = new Date(toIsoJst(m[1]));
    flagged++;
    console.log(`${file}  ${key}="${m[1]}"`);
    console.log(`  UTC runtime: ${wrong.toISOString()} / intended JST: ${right.toISOString()} (${(wrong - right) / 3600000}h)`);
    if (wrong.toISOString().slice(0, 10) !== right.toISOString().slice(0, 10)) {
      console.log("  ⚠ a date-only lastmod would be off by a day");
    }
  }
}
console.log(flagged ? `Offset-less values: ${flagged}` : "No offset-less dates found");
process.exitCode = flagged ? 1 : 0;

Running it against three sample files — an early-morning time, a date-only value, and an updated field — flagged all three with a nine-hour gap, and the first two with a day-level shift as well. Anything before 9 a.m. JST falls on the previous day in UTC, so even a sitemap that only emits dates gets the day wrong.

A non-zero count isn't a bug by itself; it just tells you where the conversion has to happen. What really needs checking is the conversion, so I pinned the tests to a time zone and ran them three times:

// dates.test.mjs — usage: TZ=UTC node --test dates.test.mjs
import test from "node:test";
import assert from "node:assert/strict";
import { toIsoJst } from "./to-iso-jst.mjs";
 
test("offset-less date-times are read as JST", () => {
  assert.equal(new Date(toIsoJst("2026-03-22T05:30")).toISOString(), "2026-03-21T20:30:00.000Z");
});
test("date-only values become JST midnight", () => {
  assert.equal(new Date(toIsoJst("2026-03-22")).toISOString(), "2026-03-21T15:00:00.000Z");
});
test("values with an offset pass through untouched", () => {
  assert.equal(toIsoJst("2026-03-22T10:00:00+09:00"), "2026-03-22T10:00:00+09:00");
});

All three passed under UTC, Asia/Tokyo, and America/Los_Angeles. Prefixing the test command with TZ=UTC is all it takes to check under production conditions from a JST laptop.

Still wrong after the fix? Find the call that skipped the conversion

If production lastmod still points into the future, some call site is bypassing the function. The fastest check I found was reading the deployed sitemap and counting future timestamps:

// future-lastmod.mjs — usage: node future-lastmod.mjs https://example.com/sitemap.xml
import { readFileSync } from "node:fs";
 
const src = process.argv[2];
const xml = src.startsWith("http") ? await (await fetch(src)).text() : readFileSync(src, "utf8");
const now = Date.now();
const future = [...xml.matchAll(/<loc>([^<]+)<\/loc>\s*<lastmod>([^<]+)<\/lastmod>/g)]
  .map(([, loc, lastmod]) => ({ loc, lastmod, ahead: (Date.parse(lastmod) - now) / 3600000 }))
  .filter((r) => r.ahead > 0.1); // allow a little clock skew
 
for (const r of future) console.log(`${r.ahead.toFixed(1)}h ahead  ${r.lastmod}  ${r.loc}`);
console.log(future.length ? `Future lastmod entries: ${future.length}` : "No future lastmod entries");
process.exitCode = future.length ? 1 : 0;

If even one entry shows up, search the repo for new Date( and check each call whose argument comes from frontmatter. When I hand this to an Antigravity agent, I split the investigation from the fix: "List every new Date( call, and for the ones whose argument comes from frontmatter date or updated, make a table showing whether they go through the conversion function. Don't change anything yet." Ask for both at once, and display code that already works correctly with a timeZone option can get swept into the rewrite. Reading the table myself first ends up being the faster path.

You could also rewrite every frontmatter value to include +09:00. I'd rather not: it makes a huge diff and invites misses. Normalizing in one place on the reading side felt safer to me.

If you want to rethink timestamp handling more broadly, including day boundaries and daylight saving time, I wrote up how I tackled the same class of problem on the app side in the notes on yesterday's wallpaper showing up again at midnight.

For a next step, try running future-lastmod.mjs once against your own sitemap. If it comes back with zero, that's one less thing to wonder about.

Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

▣ App Dev2026-10-28
I Fetched All 155 Sitemap URLs. Every One Returned 200, but 93% of the lastmod Dates Were the Same Day
A record of fetching every sitemap URL and cross-checking status, canonical, hreflang and lastmod. Full standard-library Python scripts and the mismatch I found.
▣ App Dev2026-10-18
Before Letting an Agent Touch My Config, I Found That .env* Doesn't Cover .dev.vars, and Wrote a Preflight Script
Auditing my own Cloudflare Workers repo showed that the .env* line in .gitignore never protected .dev.vars. Here is the full Python script that asks git itself where secrets can leak before an agent opens the repo.
▣ App Dev2026-11-12
Check Web Font Delivery with an Origin Header, Too: How a Fallback Font Went Unnoticed on My Site for 13 Days
For 13 days, the Latin web font on my own site kept returning 404 and every page was drawn in a fallback face. A plain curl returned 200; only the browser's request, which carries an Origin header, received the stale 404. Here is a script that compares three kinds of request, a setting that keeps long cache lifetimes off error responses, and how to pick a purge that reaches every variant.