<?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[Suanmingku]]></title><description><![CDATA[Suanmingku]]></description><link>https://suanmingku.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 13:00:07 GMT</lastBuildDate><atom:link href="https://suanmingku.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Engineering an Accurate BaZi (Four Pillars) Calendar Engine: Solar Longitude, Equation of Time, and the Zi Hour Edge Case]]></title><description><![CDATA[Most online Chinese astrology calculators get a surprising number of charts wrong — not because of interpretation differences, but because of calendar and…]]></description><link>https://suanmingku.hashnode.dev/engineering-an-accurate-bazi-four-pillars-calendar-engine-solar-longitude-equation-of-time-and-the-zi-hour-edge-case</link><guid isPermaLink="true">https://suanmingku.hashnode.dev/engineering-an-accurate-bazi-four-pillars-calendar-engine-solar-longitude-equation-of-time-and-the-zi-hour-edge-case</guid><category><![CDATA[algorithms]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Software Engineering]]></category><dc:creator><![CDATA[Poon ZHIHOU]]></dc:creator><pubDate>Tue, 24 Nov 2026 08:24:57 GMT</pubDate><content:encoded><![CDATA[<p>Most online Chinese astrology calculators get a surprising number of charts wrong — not because of interpretation differences, but because of <strong>calendar and astronomical math bugs</strong>.</p>
<p>While building <a href="https://suanmingku.com/">Suanmingku</a> — a free, open-access, zero-login classical Chinese calendar and <a href="https://suanmingku.com/en">bazi calculator</a> — we ran into four classic engineering pitfalls that break naive implementations. Here is how they work under the hood and how to solve them deterministically without relying on hardcoded lookup tables or LLM guesswork.</p>
<h2>Pitfall 1: Using Gregorian Months or Lunar New Year Instead of Solar Terms (Jieqi)</h2>
<p>A common bug in hobbyist BaZi scripts is flipping the <strong>Year Pillar</strong> on January 1 (Gregorian) or even on Chinese New Year (Lunar Jan 1).</p>
<p>In classical Four Pillars (BaZi) calculation:</p>
<ul>
<li>The <strong>Year Pillar</strong> switches at <strong>Lichun (立春, Start of Spring)</strong> — the exact astronomical instant when the Sun's apparent ecliptic longitude reaches <strong>315°</strong>.</li>
<li>Each <strong>Month Pillar</strong> switches at one of the 12 major <strong>Jie (節)</strong> solar terms (315°, 345°, 15°, 45°, ..., 285°), <em>not</em> on the 1st of the Gregorian or lunar month.</li>
</ul>
<p>Because Earth's orbit is elliptical (Kepler's Second Law), the interval between solar terms varies from ~29.4 days in winter to ~31.4 days in summer. Computing solar longitude via VSOP87 / Meeus astronomical algorithms (or exact ephemeris interpolation) to minute-level precision is essential for anyone born within 24 hours of a solar-term boundary.</p>
<h2>Pitfall 2: Clock Time vs. True Solar Time (真太陽時)</h2>
<p>Standard civil time zones can deviate dramatically from local solar noon. For example, someone born in Urumqi (87.6°E) using Beijing Time (120°E standard meridian) has a longitude offset of <strong>-129.6 minutes</strong> — more than an entire two-hour Chinese shichen (時辰)!</p>
<p>To compute <strong>True Solar Time</strong> accurately, a calendar engine must apply two corrections to civil clock time:</p>
<ol>
<li><strong>Longitude Offset (Mean Solar Time)</strong>:
<code>delta_longitude_min = (local_longitude - timezone_meridian) * 4</code> minutes</li>
<li><strong>Equation of Time (EoT, 均時差)</strong>:
Due to Earth's axial tilt (23.44°) and orbital eccentricity, apparent solar time drifts between <strong>-14.2 minutes</strong> (mid-February) and <strong>+16.4 minutes</strong> (early November) relative to mean solar time.</li>
</ol>
<p>Combining both gives:
<code>True Solar Time = Civil Time - DST + Longitude Offset + Equation of Time</code></p>
<p>Skipping either correction routinely shifts the <strong>Hour Pillar</strong> — and for late-night births, shifts the <strong>Day Pillar</strong> as well.</p>
<h2>Pitfall 3: The Early Zi vs. Late Zi Hour Boundary (23:00–00:59)</h2>
<p>In traditional Chinese timekeeping, the <strong>Zi Hour (子時)</strong> spans <strong>23:00 to 00:59</strong>, straddling midnight. Two classical schools exist for births between <strong>23:00 and 23:59</strong> (Late Zi / 晚子時):</p>
<ul>
<li>Advance the Day Pillar at 23:00, OR</li>
<li>Keep the current Day Pillar until 00:00 while deriving the Hour Stem from the next day's rule (五鼠遁).</li>
</ul>
<p>Rather than silently forcing one undocumented assumption, a well-engineered calculator should expose this cleanly and compute the Sexagenary Day Cycle (干支紀日) directly from the <strong>Julian Day Number (JDN)</strong> so leap years, Gregorian calendar reforms (1582), and century boundaries never drift.</p>
<h2>Pitfall 4: Deterministic Rules vs. LLM Hallucinations</h2>
<p>Many recent "AI fortune" web apps pass a raw birth date directly to an LLM prompt and ask it to output a BaZi chart. Even frontier LLMs frequently hallucinate Heavenly Stems, miscompute Lichun crossings, or mix up Ten Gods (十神) relationships.</p>
<p>A far cleaner architecture separates concerns completely:</p>
<ul>
<li><strong>100% deterministic astronomical &amp; classical rule engine</strong> for Four Pillars, Ten Gods, Hidden Stems (藏干), 10-year Luck Pillars (大運), Five-Element scoring, Zi Wei Dou Shu, and Liu Yao hexagrams.</li>
<li><strong>Zero login, zero personal birth-data retention</strong> (client-side/ephemeral processing with automatic 24-hour draft clearing) and native PDF print export.</li>
</ul>
<h2>Try the Engine Live</h2>
<p>You can inspect the live output — including True Solar Time breakdown, solar-term transitions, Hidden Stems, and multi-school classical charts — on <a href="https://suanmingku.com/en">Suanmingku's free BaZi calculator</a> (also available in Traditional Chinese at <a href="https://suanmingku.com/">suanmingku.com</a> and Japanese at <code>/ja</code>). Everything runs openly with no account wall and no AI chat fluff — just clean lunisolar calendar engineering and classical texts.</p>
]]></content:encoded></item></channel></rss>