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

Handling Historical DST Folds, Non-Existent Spring Clock Times, and 23:00 Day Boundaries in JavaScript

If you have ever built a calendar converter, scheduling app, or historical date tool, you already know that JavaScript's built-in Date object hides the nastiest parts of civil time. While building the free English BaZi

If you have ever built a calendar converter, scheduling app, or historical date tool, you already know that JavaScript's built-in Date object hides the nastiest parts of civil time.

While building the free English BaZi (Chinese Four Pillars) calculator at MingShu (mingshu.art), we ran straight into a set of real-world civil time bugs that silently break most online calculatorsβ€”especially for users born outside China between 1901 and today.

Here are the four trickiest edge cases we had to solve, why naive implementations fail on them, and the exact reproducible test cases we use to verify our engine.

1. The 1986–1991 China Daylight Saving Trap

Many developers assume China (Asia/Shanghai) has always been a flat UTC+08:00. It hasn't. Mainland China observed daylight saving time every summer from 1986 through 1991.

Now combine that with a traditional BaZi rule: the Day Pillar rolls forward at 23:00 local standard time (the start of the Zi / Rat double-hour), not midnight.

Consider a real birth certificate reading:

  • Date & Time: 1990-07-15 23:30
  • Zone: Asia/Shanghai

A naive calculator sees 23:30, thinks "past 23:00!", and rolls the Day Pillar to the next day.

In reality, on July 15, 1990, Shanghai was on civil daylight time (UTC+09:00). Restoring that instant to local standard time (UTC+08:00) puts the actual standard clock at 22:30β€”before the 23:00 boundary. That single historical hour changes both the Day Pillar and the Hour Pillar (θΎ›ε·³ / ε·±δΊ₯ instead of the next day's pillars).

Fix: Never assume a zone's current UTC offset applies to historical dates. Always resolve civil timestamps through a pinned historical IANA tzdb release (we pin @tubular/time with IANA tzdb 2026e).

2. Autumn Rollbacks: When 01:30 Happened Twice (DST Fold)

On October 28, 1990, clocks in America/New_York fell back from 02:00 EDT (-04:00) to 01:00 EST (-05:00).

That means 1990-10-28 01:30 occurred twice on the same night:

  1. First occurrence: 01:30 EDT (-04:00) β†’ standard time 00:30 β†’ Hour Pillar 戊子
  2. Second occurrence: 01:30 EST (-05:00) β†’ standard time 01:30 β†’ Hour Pillar ε·±δΈ‘

Most libraries silently pick one (disambiguation: "compatible" or "earlier") and render a confident-looking answer that has a 50% chance of being wrong.

Fix: Treat an unresolved DST fold as a multi-candidate state. On MingShu (mingshu.art), we display the three certain pillars (庚午 / δΈ™ζˆŒ / δΈ™ε―…), mark the Hour Pillar explicitly Uncertain, and surface both offset choices (UTC-04:00 vs UTC-05:00) so the user can confirm which one matches their birth record.

3. Spring Forward: When 02:30 Never Existed (DST Gap)

On April 1, 1990, clocks in America/New_York jumped directly from 01:59 EST to 03:00 EDT. The timestamp 1990-04-01 02:30 never legally existed on local wall clocks.

Silently shifting 02:30 forward to 03:30 hides transcription errors on birth records.

Fix: Reject non-existent local clock times with a structured CLOCK_GAP correction response, preserve the user's input, and offer the nearest legal minutes (01:59 -05:00 or 03:00 -04:00) or an explicit "unknown birth time" option.

4. Unknown or Approximate Birth Times (Why Guessing Noon Breaks Math)

A surprisingly high percentage of users don't know their exact birth minuteβ€”or only know a rough window from a parent, like "between 10:30 PM and 11:30 PM."

Many legacy forms force a required time input and tell users to type 12:00. That quietly injects a fabricated Hour Pillar into every downstream calculation.

Instead, we model three explicit precision states (exact, approximate, unknown):

  • unknown (1990-05-15, America/New_York): Evaluates all 12 valid two-hour branches across the day, displays only pillars shared across every candidate (庚午 / θΎ›ε·³ / 庚辰), and leaves the Hour Pillar explicitly blank.
  • approximate crossing 23:00 (1990-01-01 22:30–23:30, Asia/Shanghai): Because the window straddles the 23:00 day boundary, even the Day Pillar disagrees across candidates (δΈ™ε―…/ε·±δΊ₯ vs 丁卯/庚子)β€”so both Day and Hour stay explicitly uncertain rather than picking one arbitrarily.

7 Reproducible Boundary Test Cases

If you are building any calendar or historical timezone toolβ€”or just want to test how different BaZi calculators handle edge casesβ€”we published all 7 synthetic test cases publicly:

Have you run into any historical timezone edge cases in Temporal or IANA tzdb that surprised you? Drop them in the commentsβ€”I'd love to compare notes.

πŸ“° 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.