@openfate/bazi-engine 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +25 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -92,7 +92,7 @@ function createLunarDateTime(solarDateTime) {
92
92
  * ```
93
93
  */
94
94
  function calculateBaziChart(input) {
95
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
95
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
96
96
  (0, validation_1.validateBaziInput)(input);
97
97
  let solarYear = input.year;
98
98
  let solarMonth = input.month;
@@ -158,8 +158,26 @@ function calculateBaziChart(input) {
158
158
  algorithm: detail.algorithm,
159
159
  };
160
160
  }
161
+ else if (((_e = input.dstOffset) !== null && _e !== void 0 ? _e : 0) !== 0 && input.hour !== undefined) {
162
+ // ── 2b. DST normalization without True Solar Time ────────────────────
163
+ // DST is a civil-clock correction, not a solar-time refinement: a birth
164
+ // recorded at 15:20 during a DST period (e.g. China 1986–1991 summer,
165
+ // Taiwan 1946–1961) actually occurred at 14:20 standard time. The TST
166
+ // path above already subtracts dstOffset inside calculateTrueSolarTime;
167
+ // when TST is disabled it must still be normalized out here, otherwise
168
+ // the pillars use the shifted clock hour — a wrong 时辰, and near
169
+ // midnight a wrong day pillar. Date-based math keeps day/month/year
170
+ // rollover safe (lunar input was already converted to solar above).
171
+ const shifted = new Date(Date.UTC(solarYear, solarMonth - 1, solarDay, solarHour, solarMinute));
172
+ shifted.setUTCMinutes(shifted.getUTCMinutes() - Math.round(((_f = input.dstOffset) !== null && _f !== void 0 ? _f : 0) * 60));
173
+ solarYear = shifted.getUTCFullYear();
174
+ solarMonth = shifted.getUTCMonth() + 1;
175
+ solarDay = shifted.getUTCDate();
176
+ solarHour = shifted.getUTCHours();
177
+ solarMinute = shifted.getUTCMinutes();
178
+ }
161
179
  // ── 3. Generate Four Pillars ─────────────────────────────────────────────
162
- const { pillars, eightChar, dayStem } = (0, pillars_1.generatePillarsFromSolar)(solarYear, solarMonth, solarDay, solarHour, solarMinute, solarSecond, (_e = input.dayBoundaryMode) !== null && _e !== void 0 ? _e : 'MIDNIGHT_00');
180
+ const { pillars, eightChar, dayStem } = (0, pillars_1.generatePillarsFromSolar)(solarYear, solarMonth, solarDay, solarHour, solarMinute, solarSecond, (_g = input.dayBoundaryMode) !== null && _g !== void 0 ? _g : 'MIDNIGHT_00');
163
181
  // ── 4. Day Master ────────────────────────────────────────────────────────
164
182
  const dayMaster = (0, pillars_1.getStemInfo)(dayStem);
165
183
  // ── 5. Da Yun Cycles ─────────────────────────────────────────────────────
@@ -169,7 +187,7 @@ function calculateBaziChart(input) {
169
187
  year: pillars.year.branch,
170
188
  month: pillars.month.branch,
171
189
  day: pillars.day.branch,
172
- hour: (_g = (_f = pillars.hour) === null || _f === void 0 ? void 0 : _f.branch) !== null && _g !== void 0 ? _g : '',
190
+ hour: (_j = (_h = pillars.hour) === null || _h === void 0 ? void 0 : _h.branch) !== null && _j !== void 0 ? _j : '',
173
191
  });
174
192
  const calculationSolar = createDateTime(solarYear, solarMonth, solarDay, input.hour === undefined ? undefined : solarHour, input.hour === undefined ? undefined : solarMinute, input.hour === undefined ? undefined : solarSecond);
175
193
  const lunarCalendar = createLunarDateTime(calculationSolar);
@@ -188,10 +206,10 @@ function calculateBaziChart(input) {
188
206
  },
189
207
  metadata: {
190
208
  trueSolarTimeApplied: enableTST,
191
- dayBoundaryMode: (_h = input.dayBoundaryMode) !== null && _h !== void 0 ? _h : 'MIDNIGHT_00',
192
- longitude: (_j = input.longitude) !== null && _j !== void 0 ? _j : null,
193
- timezoneBasis: (_l = (_k = input.timezone) !== null && _k !== void 0 ? _k : input.timezoneId) !== null && _l !== void 0 ? _l : null,
194
- dstOffset: (_m = input.dstOffset) !== null && _m !== void 0 ? _m : 0,
209
+ dayBoundaryMode: (_k = input.dayBoundaryMode) !== null && _k !== void 0 ? _k : 'MIDNIGHT_00',
210
+ longitude: (_l = input.longitude) !== null && _l !== void 0 ? _l : null,
211
+ timezoneBasis: (_o = (_m = input.timezone) !== null && _m !== void 0 ? _m : input.timezoneId) !== null && _o !== void 0 ? _o : null,
212
+ dstOffset: (_p = input.dstOffset) !== null && _p !== void 0 ? _p : 0,
195
213
  },
196
214
  };
197
215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfate/bazi-engine",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Accurate Four Pillars (八字) chart engine with True Solar Time correction, Da Yun cycles, and interaction detection. Extracted from the OpenFate.ai core engine.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",