<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mike Mait]]></title><description><![CDATA[Mike Mait]]></description><link>https://mike-mait.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 20:47:53 GMT</lastBuildDate><atom:link href="https://mike-mait.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The timezone bugs you don't know you have (and how to find them)]]></title><description><![CDATA[Most production apps quietly corrupt data on DST transition day. The 5 timezone bugs hiding in your code — with one-liner tests to find them.]]></description><link>https://mike-mait.hashnode.dev/the-timezone-bugs-you-don-t-know-you-have-and-how-to-find-them</link><guid isPermaLink="true">https://mike-mait.hashnode.dev/the-timezone-bugs-you-don-t-know-you-have-and-how-to-find-them</guid><category><![CDATA[webdev]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[timezone]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[api]]></category><dc:creator><![CDATA[mikemaittech]]></dc:creator><pubDate>Wed, 29 Apr 2026 16:52:03 GMT</pubDate><content:encoded><![CDATA[<p>A user reports that a meeting fired an hour late. You check the database — the timestamp looks fine. You check the UI — the display matches what the user entered. Then you realize: today was DST transition day.</p>
<p>This post is about the timezone bugs that 90% of production apps have and don't know about. None of these are exotic. All of them are quietly corrupting data in some app you've shipped.</p>
<h2>Bug #1: The Spring-Forward Gap</h2>
<p>On March 8, 2026 in <code>America/New_York</code>, clocks jump from 1:59:59 directly to 3:00:00. The entire 2:00–2:59 hour does not exist.</p>
<p>If a user enters "2:30am" in your scheduler:</p>
<pre><code class="language-javascript">const dt = DateTime.fromISO("2026-03-08T02:30:00", { zone: "America/New_York" });
console.log(dt.toISO());
// "2026-03-08T03:30:00.000-04:00"  ← Luxon silently shifted it to 3:30
</code></pre>
<p>Luxon "helpfully" resolved the invalid time forward. Your user wanted 2:30am. You stored 3:30am. They have no idea. The bug surfaces 8 months later when their recurring event fires an hour late.</p>
<p><strong>The fix:</strong> explicitly check whether a parsed datetime equals what you asked for, and reject (or escalate to the user) if it doesn't. Don't trust your library to "just handle it."</p>
<h2>Bug #2: The Fall-Back Overlap</h2>
<p>On November 1, 2026 in <code>America/New_York</code>, clocks go from 1:59:59 back to 1:00:00. The 1:00–1:59 hour happens twice. "1:30am" is genuinely ambiguous.</p>
<pre><code class="language-javascript">const dt = DateTime.fromISO("2026-11-01T01:30:00", { zone: "America/New_York" });
console.log(dt.offset);
// -240 (EDT) — but it could just as legitimately be -300 (EST)
</code></pre>
<p>Most libraries pick one without telling you. Picking "the first occurrence" is a real business decision (your user might mean the second). It should not be a silent default.</p>
<p><strong>The fix:</strong> when you detect an ambiguous local time, force a policy decision in your domain layer. Log it. Don't let the library guess.</p>
<h2>Bug #3: Non-Whole-Hour Offsets</h2>
<p>Pop quiz — what's the offset for <code>Asia/Kathmandu</code>? Most developers say "+5:30." Wrong, that's India.</p>
<ul>
<li>Nepal: <strong>UTC+5:45</strong></li>
<li>Chatham Islands: <strong>UTC+12:45</strong></li>
<li>Lord Howe Island uses a <strong>30-minute</strong> DST shift, not 60</li>
</ul>
<p>If your code anywhere does <code>offset / 60</code> to get hours, or assumes the minutes component is always 0 or 30, you have a bug. It might never fire, because you might never have a Nepali user. Until you do.</p>
<p><strong>The fix:</strong> treat offsets as minutes-from-UTC, never as hours. Format defensively. Test with Kathmandu in your suite.</p>
<h2>Bug #4: Historical Zone Rules</h2>
<p>Germany on 1945-05-24 had a 23:00 → 01:00 jump (the occupation forces synchronized clocks). Russia in 2011 abolished DST permanently. Iran abolished DST in 2022. Egypt re-instated it in 2023. Samoa literally skipped December 30, 2011 to switch date lines.</p>
<p>If you're storing or computing historical timestamps — billing periods that started years ago, audit trails, IoT data from old devices — your results may be wrong by an hour for any user in an affected zone.</p>
<p><strong>The fix:</strong> if you're computing across years, pin your tzdata version explicitly and document it. Don't assume the runtime's bundled tzdata is up to date.</p>
<h2>Bug #5: tzdb Update Drift</h2>
<p>The IANA tzdata gets updated 3-6 times per year. Every release fixes historical errors and adds new rule changes (countries change DST policy all the time — Mexico in 2022, Egypt in 2023, BC's pending change in 2026).</p>
<p>Your Node.js version was built with a snapshot of tzdata from whenever it was released. If you're on Node 20 from 2023, you're on tzdata from 2023. You're missing every IANA update since then.</p>
<p>This means <strong>your app gives wrong answers for any zone whose rules changed after your Node version's release date</strong>. Often by an hour, often silently.</p>
<p><strong>The fix:</strong> decouple tzdata from your runtime version. Use a userland tzdb package you can update independently. I just did this for my production system and wrote up the migration if you want details.</p>
<h2>How to test for these in your own code</h2>
<p>For each of the bugs above, here's a one-liner test:</p>
<pre><code class="language-javascript">// Bug #1 detection
function isValidLocalDatetime(input, zone) {
  const dt = DateTime.fromISO(input, { zone });
  // Compare requested local time vs what the lib gave back
  return dt.toFormat("yyyy-MM-dd'T'HH:mm:ss") === input;
}

// Bug #2 detection
function isAmbiguousLocalDatetime(input, zone) {
  const dt = DateTime.fromISO(input, { zone });
  const before = dt.minus({ hours: 1 });
  const after = dt.plus({ hours: 1 });
  return before.offset !== after.offset;
}
</code></pre>
<p>Run these against your top 50 customers' time zones for the next 5 years worth of DST transition dates. If you find a bug, congrats — you found one that probably already cost you a support ticket.</p>
<h2>My take</h2>
<p>I got tired of writing this code in every project. So I built <a href="https://chronoshieldapi.com">ChronoShield API</a> — a REST API that handles all of these cases as a service. Today's launch:</p>
<ul>
<li><code>npm install chronoshield</code> / <code>pip install chronoshield</code></li>
<li>Free tier: 1k req/mo</li>
<li>Currently serving IANA tzdata 2026b (latest), with the BC permanent-DST projection already live</li>
<li>Endpoints: <code>/validate</code>, <code>/resolve</code>, <code>/convert</code>, <code>/version</code></li>
</ul>
<p>But the test cases above work whether or not you use the API. If you take nothing else from this post — write the tests. They'll find bugs you didn't know you had.</p>
]]></content:encoded></item></channel></rss>