<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: FateMaster</title>
    <description>The latest articles on DEV Community by FateMaster (@fatemaster).</description>
    <link>https://dev.to/fatemaster</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4280855%2F9e81f094-8b96-4205-9256-b3dce7e6a012.jpg</url>
      <title>DEV Community: FateMaster</title>
      <link>https://dev.to/fatemaster</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fatemaster"/>
    <language>en</language>
    <item>
      <title>The Timekeeping Bugs That Silently Break BaZi (Four Pillars) Charts</title>
      <dc:creator>FateMaster</dc:creator>
      <pubDate>Thu, 03 Dec 2026 14:16:22 +0000</pubDate>
      <link>https://dev.to/fatemaster/the-timekeeping-bugs-that-silently-break-bazi-four-pillars-charts-bnp</link>
      <guid>https://dev.to/fatemaster/the-timekeeping-bugs-that-silently-break-bazi-four-pillars-charts-bnp</guid>
      <description>&lt;p&gt;&lt;em&gt;Why timezone offsets, Gregorian midnights, and Lunar New Year are the wrong primitives for Chinese calendar math.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you have ever shipped a BaZi (Four Pillars of Destiny) calculator, there is a good chance the first version was wrong in a quiet, confident way. You accepted a birth &lt;code&gt;Date&lt;/code&gt;, mapped &lt;code&gt;getHours()&lt;/code&gt; onto the twelve earthly branches, treated January 1 — or Chinese New Year — as the year boundary, and returned eight characters. For many birth times the result looked plausible. Near a boundary, it was a different chart.&lt;/p&gt;

&lt;p&gt;BaZi encodes a birth as four stem-and-branch pairs, one each for year, month, day, and hour. Those pillars are not labels for civil calendar units. They are labels for the Sun's position and for local apparent solar time. If your engine starts from timezone-aware midnight math, you are using the wrong coordinate system.&lt;/p&gt;

&lt;p&gt;This post walks through the three bugs that show up most often, with a compact TypeScript snippet you can actually run.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The civil clock is not where the Sun is
&lt;/h2&gt;

&lt;p&gt;A hospital records clock time: a legal time zone, sometimes daylight saving, and a civil date. Traditional hour branches follow &lt;em&gt;true solar time&lt;/em&gt; — the time a sundial would show at that longitude.&lt;/p&gt;

&lt;p&gt;Getting from one to the other is a short pipeline, and every step can move a birth across a two-hour hour-pillar boundary:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Roll back daylight saving.&lt;/strong&gt; The recorded hour may already be an hour ahead of standard time. China itself used DST from 1986 to 1991, so this is not only a "US and Europe" problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Correct for longitude.&lt;/strong&gt; Standard time assumes a zone meridian (120°E for China UTC+8, 75°W for US Eastern, and so on). Apparent noon arrives four minutes later for every degree west of that meridian.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply the equation of time.&lt;/strong&gt; Earth's elliptical orbit and axial tilt make apparent solar time drift from mean solar time by as much as about 16 minutes fast in early November and 14 minutes slow in mid-February.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;China makes the longitude term impossible to ignore. The whole country uses a single official zone on the 120°E meridian. Beijing at 116.4°E is only about 14 minutes behind that meridian. Ürümqi, near 87.6°E, is about &lt;strong&gt;2 hours and 10 minutes&lt;/strong&gt; behind. Add a February equation of time and a birth recorded at 01:00 standard time can still be in the previous earthly branch — and sometimes on the previous day pillar.&lt;/p&gt;

&lt;p&gt;Here is a compact, educational conversion. The equation-of-time polynomial is the common NOAA approximation; it is usually accurate to under a minute, which is enough to reason about hour pillars. A production engine should still use a proper solar ephemeris and historical timezone data, not this snippet alone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CivilTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 1–12&lt;/span&gt;
  &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// 0–23, DST already removed&lt;/span&gt;
  &lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/** Equation of time in minutes: apparent solar time minus mean solar time. */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;equationOfTimeMinutes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CivilTime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;utc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;month&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dayOfYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;86_400_000&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;gamma&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;365&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dayOfYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="mf"&gt;229.18&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.000075&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
      &lt;span class="mf"&gt;0.001868&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gamma&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
      &lt;span class="mf"&gt;0.032077&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gamma&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
      &lt;span class="mf"&gt;0.014615&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;gamma&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
      &lt;span class="mf"&gt;0.040849&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;gamma&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/** True solar minutes from local midnight. May be negative or &amp;gt;= 1440 near day edges. */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;trueSolarMinutes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CivilTime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;longitudeDeg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;// east positive&lt;/span&gt;
  &lt;span class="n"&gt;standardMeridianDeg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// 120 for China, -75 for US Eastern, 15 * UTC offset&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;longitudeMinutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;longitudeDeg&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;standardMeridianDeg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;longitudeMinutes&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;equationOfTimeMinutes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/** 0 = Zi (子), 1 = Chou (丑), … 11 = Hai (亥). Zi runs 23:00–01:00. */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hourBranchIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trueSolarMin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trueSolarMin&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1440&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1440&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1440&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1440&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A concrete check: Beijing, 116.4°E, 10 February, 23:20 standard time. Longitude offset ≈ −14.4 minutes. Equation of time ≈ −14.2 minutes. True solar time is about &lt;strong&gt;22:51&lt;/strong&gt;, which is Hai, not Zi. A naive &lt;code&gt;hour === 23 → Zi&lt;/code&gt; mapping gets the hour pillar wrong — and this birth is not even close to a remote western longitude.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;+ 60&lt;/code&gt; shift in &lt;code&gt;hourBranchIndex&lt;/code&gt; is load-bearing. Zi is the two-hour block that &lt;em&gt;straddles civil midnight&lt;/em&gt;. If you write &lt;code&gt;Math.floor(hour / 2)&lt;/code&gt;, 23:00–23:59 collapses into Hai, and every late-night birth in your database is off.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Year and month pillars follow solar terms, not calendars
&lt;/h2&gt;

&lt;p&gt;The second family of bugs comes from treating "year" and "month" as calendar dates.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;year pillar&lt;/strong&gt; changes at Lichun (立春, Start of Spring), an astronomical instant usually on February 3–5, when the Sun's ecliptic longitude reaches 315°. It does &lt;strong&gt;not&lt;/strong&gt; change on January 1, and it does &lt;strong&gt;not&lt;/strong&gt; change at Lunar New Year. Someone born in late January can belong to the previous year's pillar; someone born a few days after Lunar New Year but still before Lichun can too.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;month pillar&lt;/strong&gt; changes at the twelve &lt;em&gt;Jie&lt;/em&gt; (节) among the twenty-four solar terms — Lichun, Jingzhe, Qingming, Lixia, and so on — not on the first of a Gregorian month, and not on the first of a lunar month. The twelve &lt;em&gt;Qi&lt;/em&gt; (气 / 中气), including Chunfen and Dongzhi, sit near mid-month and do not open a new BaZi month.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A solar term is a &lt;em&gt;moment&lt;/em&gt;, not a calendar day. If Lichun falls at 16:25 local apparent time, a morning birth and an evening birth on the same civil date can have different year &lt;em&gt;and&lt;/em&gt; month pillars. Looking up "Lichun = February 4" and comparing dates at midnight will misfire for anyone born on that day.&lt;/p&gt;

&lt;p&gt;The same warning applies if you convert a lunar birthday and then trust the lunar month number. Lunar months track the Moon; BaZi month branches track the Sun.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The day pillar and the Zi-hour debate
&lt;/h2&gt;

&lt;p&gt;Because Zi runs from 23:00 to 01:00 true solar time, a single hour branch occupies two civil dates. That forces an explicit rule, not a &lt;code&gt;Date&lt;/code&gt; default:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A birth at 23:30 is still on the previous civil date, already in Zi.&lt;/li&gt;
&lt;li&gt;A birth at 00:30 is on the new civil date, still in Zi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Schools disagree about when the &lt;em&gt;day pillar&lt;/em&gt; flips: at 23:00, when Zi begins (子初换日), or at midnight (子正). Neither choice is something JavaScript will infer for you. Pick a rule, document it, and apply it &lt;em&gt;after&lt;/em&gt; true-solar-time conversion. Applying it to the civil clock, then converting, will desynchronize the day and hour pillars around midnight.&lt;/p&gt;

&lt;p&gt;Date-library defaults are a related trap. &lt;code&gt;new Date('1988-07-15')&lt;/code&gt; is midnight UTC in many engines. Combine that with a forgotten DST rollback in a year when the country observed DST, and you can shift the hour pillar even when the user typed a precise local time.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical checklist
&lt;/h2&gt;

&lt;p&gt;Before you trust a generated chart, verify the engine against cases like these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A late-January birth, and a birth on a Lichun day on both sides of the exact instant.&lt;/li&gt;
&lt;li&gt;A birth at 23:10 and 00:20 in the same location, after true-solar conversion.&lt;/li&gt;
&lt;li&gt;A far-from-meridian location in a wide zone (western China is the stress test; rural longitudes in any large zone also work).&lt;/li&gt;
&lt;li&gt;A birth during a historical DST period, using the zone rules that applied &lt;em&gt;in that year&lt;/em&gt;, not today's rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chart casting should be deterministic: the same inputs must yield the same eight characters every time. Interpretation can be a separate layer; the calendar math should not be.&lt;/p&gt;

&lt;p&gt;If you want a live engine to compare edge cases against, &lt;a href="https://www.fatemaster.ai/en" rel="noopener noreferrer"&gt;FateMaster&lt;/a&gt; publishes an English &lt;a href="https://www.fatemaster.ai/en/workspace/bazi-calculate" rel="noopener noreferrer"&gt;BaZi calculator&lt;/a&gt; that casts the Four Pillars from true solar time — longitude, equation of time, and historical DST included — before any reading is attached. Use it as a reference implementation, not as a substitute for writing tests around your own boundary cases.&lt;/p&gt;

&lt;p&gt;The underlying idea is older than time zones: the pillars track the Sun. Once your code does the same, the surprising charts near midnights, solar terms, and zone edges stop being surprises. They are the system working correctly.&lt;/p&gt;

</description>
      <category>astronomy</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
