When users compare two Chinese Four Pillars (BaZi) apps—or ask an LLM to compute their birth chart—they often get different Hour or Year Pillars for the exact same birthday.
In our first engineering note, we covered why SolarPillar splits deterministic astronomical calculation from AI prose generation. Here are three production edge cases we had to solve in TypeScript so edge-case users never receive silent math bugs or double-charged AI credits.
1. Historical IANA DST Disambiguation (And Fall-Back 1:30 AM)
A standard JavaScript Date is bad at answering a simple question: what UTC instant did 1994-11-06 01:30 represent in America/New_York?
On fall-back Daylight Saving transitions, 01:30 AM happens twice—once in EDT (UTC-4) and once in EST (UTC-5). On spring-forward transitions, 02:30 AM does not exist at all.
Instead of letting a runtime guess silently, our timezone resolver (luxon backed by IANA historical zones) resolves candidate offsets explicitly and converts the chosen UTC instant into Apparent (True) Solar Time:
Apparent Solar Time = UTC + (Birthplace Longitude / 15 deg per hr) + EquationOfTime(UTC) For European and North American users, combining historical DST correction with birthplace longitude regularly moves a birth timestamp by 40 to 90+ minutes—more than enough to flip a two-hour BaZi Hour Pillar (or cross the 23:00 Early Zi day boundary).
2. Honest 3-Pillar Unknown-Time Mode + 422 Boundary Guard
Many consumer astrology sites handle an unknown birth hour by silently inserting 12:00 PM. That quietly invents two extra BaZi characters (25% of the chart) and skews Five-Element percentages.
In SolarPillar, setting unknownTime: true computes an honest 3-Pillar chart (Year, Month, Day) and leaves the Hour Pillar explicitly unknown (full guide).
Wait—there is a subtle trap with unknownTime: true: what if the user was born on a Lichun (315 deg solar longitude) or 12-Jie monthly solar-term transition date? On those days, 04:00 vs 20:00 UTC can change the Year Pillar or Month Pillar itself.
Before letting a user spend a paid deep-reading credit, our server scans all 24 hourly UTC candidates across that local date:
export function getAmbiguousUnknownTimeReason(input: ChartInput): string | null { if (!input.unknownTime) return null; const slots = Array.from({ length: 24 }, (_, hour) => computeCandidatePillars(input, hour)); const yearSet = new Set(slots.map((s) => s.yearPillar)); if (yearSet.size > 1) return "Solar Year (Lichun) flips during this date."; const monthSet = new Set(slots.map((s) => s.monthPillar)); if (monthSet.size > 1) return "Solar Month (Jie) flips during this date."; return null; } Notice why we specifically check Year and Month pillars rather than Day pillar: because civil 23:00 Early Zi already transitions the Day pillar on almost every calendar date, checking Year/Month solar-term flips avoids false positives while blocking genuine boundary ambiguity with HTTP 422 before debiting any credit.
3. Atomic Reserve / Commit / Release + Lease Recovery for AI Reports
Once the deterministic astronomical JSON snapshot is locked, generating a full deep-reading report takes an LLM call (20–60s). Treating that as a naive decrementCredit() call breaks under concurrency or server restarts:
- Two double-clicks can unlock two parallel generations for one report.
- A process restart mid-generation leaves a user debited with no report.
Our server wraps every generation in an idempotent 3-phase ledger + lease model:
- Atomic Reserve (
POST /api/charts/:id/unlock-blueprint): Inside a serialized store mutation, verify user balance, insert a unique business key (blueprint:<chartId>:<profileVersionId>), move credits into areservedstate, and attach a 10-minuteleaseExpiresAt. - Single-Flight Execution: Concurrent requests for the same key share the active job state (
409or existing pending job) instead of spawning duplicate LLM requests. - Crash Reaper & Idempotent Release: On server startup (for interrupted inflight jobs) and via a 2-minute sweep, expired leases automatically release the
reservedledger entry back to available credits—once and only once via idempotent key lookup.
Try the Engine & Methodology
If you want to test how DST, birthplace longitude, and unknown birth times behave on real dates—or read our open calculation spec—check out:
