Saju (Korean Four Pillars) and BaZi charts are built from four pillars: year, month, day and hour. Each pillar is a pair of characters, one Heavenly Stem and…
Saju (Korean Four Pillars) and BaZi charts are built from four pillars: year, month, day and hour. Each pillar is a pair of characters, one Heavenly Stem and one Earthly Branch. The year and month pillars depend on the sun's position, which takes real astronomy. The day and hour pillars do not. They are pure calendar arithmetic. This post shows the arithmetic in JavaScript, then the one edge case that causes most disagreements between apps: births between 23:00 and midnight.
We checked the code against the sxtwl calendar library on 3,000 random dates and hours from 1900 to 2100, with zero mismatches. The 60-day cycle There are 10 Heavenly Stems and 12 Earthly Branches: js export Stems and branches advance together, one step per day. Because 10 and 12 share a factor of 2, they line up again after 60 days, not 120. So there are exactly 60 pairs, from 甲子 (index 0) to 癸亥 (index 59). pillar(i) turns an index into its pair, since index i always lands on stem i % 10 and branch i % 12.
The day count has been kept without a break for well over two thousand years. That is what makes it computable: every day since then has a fixed position in the cycle. Day pillar from a Julian Day Number A Julian Day Number (JDN) is a plain count of days. Astronomers use it so that date arithmetic never has to deal with months.
The standard conversion from a Gregorian date: Since the day cycle and the JDN both advance by one per day, the day pillar is the JDN plus a fixed offset, mod 60. The offset is 49: pillar(dayIndex(2000, 1, 1)); // '戊午' You can check the offset against any known day. January 1, 2000 has JDN 2451545 and is a 戊午 day, index 54. (2451545 + 49) mod 60 is 54. One rule matters more than the formula: use the local calendar date at the place of birth. Do not convert a New York birth to Korean time first.
Moving the date by one day changes the day pillar, and the day pillar holds the Day Master, the center of the whole chart. Hour branch The day is split into 12 two-hour blocks. The block for 子 (Rat) runs from 23:00 to 00:59, 丑 from 01:00 to 02:59, and so on: At hour 23, (23 + 1) / 2 is 12, and 12 mod 12 is 0, which is 子. At hour 0 it is 0 as well. At hour 14 it is 7, which is 未, the block from 13:00 to 14:59.
This is a source-linked briefing. Read the original report from Dev Community .