The sexagenary cycle pairs 10 Heavenly Stems with 12 Earthly Branches, giving 60 combinations (甲子 to 癸亥). English-language BaZi writing names them by polarity, element and animal: Ding-Mao (丁卯) is "Yin Fire Rabbit", Ren-Chen (壬辰) is "Yang Water Dragon". Every library I found returned only hanzi, so I put the 60-row table in one dependency-free file with a lookup and an exact day-pillar function: https://github.com/Tommyapi/jiazi (MIT).
import { dayPillar, yearPillar, lookup } from 'jiazi'; dayPillar(2027, 2, 6); // { zh: '丙辰', pinyin: 'Bing-Chen', name: 'Yang Fire Dragon', slug: 'yang-fire-dragon', // nayin: { zh: '沙中土', en: 'Sand Earth' }, ... } yearPillar(2027).name; // 'Yin Fire Goat' (Ding-Wei, the "Fire Goat" year) lookup('Ding-Mao').name; // 'Yin Fire Rabbit' The day pillar needs no solar-term math
Days are a pure 60-cycle, and 1949-10-01 is a Jia-Zi (甲子) day, so:
const days = Math.round((Date.UTC(y, m - 1, d) - Date.UTC(1949, 9, 1)) / 86400000); const pillar = JIAZI[((days % 60) + 60) % 60]; I checked it against lunar-javascript on 4,000 random dates between 1900 and 2099: 0 mismatches for the day pillar and its Na Yin (the "sound element" shared by each pair of consecutive pillars).
Year pillars are different
The BaZi year starts at Li Chun (about 4 February), not on 1 January and not at Lunar New Year. For 2027 that is 2027-02-04 09:46 China Standard Time, two days before the New Year on 2027-02-06. Someone born on 1 February 2027 belongs to BaZi year 2026. The library takes the BaZi year as input and does not compute solar terms; for month and hour pillars or Li Chun to the minute, use a full calendar library.
The same names and slugs drive the 60 Day Master pages on https://yinyangcode.com/day-master/ . Issues and corrections are welcome, especially from anyone who uses a different English naming convention.