Repository: SylarLong/iztro

Issue:
[v2.5.1]: monthly palace is incorrect when horoscope month is leap
when horoscope month is leap and date is greater than 15, the monthly palace is incorrect. for example 2020-6-7.

Discussion:

Solution patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2973e06..6682766 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,13 +7,25 @@
 - 🛠️ 修复（fix）
 - 🧹 琐事（Chore）
 
+## v2.5.2
+
+- 🛠️ 修复（fix）
+
+  🇨🇳
+
+  - 流日/流月宫位在运限月份是闰月情况下不正确。#244
+
+  🇺🇸
+
+  - monthly palace is incorrect when horoscope month is leap. #244
+
 ## v2.5.1
 
 - 🛠️ 修复（fix）
 
   🇨🇳
 
-  - 流日/流月宫位在闰月情况下不正确。#242
+  - 流日/流月宫位在生月月份是闰月情况下不正确。#242
 
   🇺🇸
 
diff --git a/package.json b/package.json
index fe22a6f..74b0610 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "iztro",
-  "version": "2.5.1",
+  "version": "2.5.2",
   "description": "轻量级紫微斗数星盘生成库。可以通过出生年月日获取到紫微斗数星盘信息、生肖、星座等信息。This is a lightweight kit for generating astrolabes for Zi Wei Dou Shu (The Purple Star Astrology), an ancient Chinese astrology. It allows you to obtain your horoscope and personality analysis.",
   "main": "lib/index.js",
   "types": "lib/index.d.ts",
@@ -69,7 +69,7 @@
   "dependencies": {
     "dayjs": "^1.11.10",
     "i18next": "^23.5.1",
-    "lunar-lite": "^0.2.3",
+    "lunar-lite": "^0.2.7",
     "lunar-typescript": "^1.7.8"
   }
 }
diff --git a/src/astro/FunctionalAstrolabe.ts b/src/astro/FunctionalAstrolabe.ts
index 74f42a3..108cb0a 100644
--- a/src/astro/FunctionalAstrolabe.ts
+++ b/src/astro/FunctionalAstrolabe.ts
@@ -39,6 +39,7 @@ const _getHoroscopeBySolarDate = (
     {
       // 运限是以立春为界，但为了满足部分流派允许配置
       year: getConfig().horoscopeDivide,
+      month: getConfig().horoscopeDivide,
     },
   );
   // 虚岁
@@ -126,11 +127,13 @@ const _getHoroscopeBySolarDate = (
   // 获取流月索引, 流年地支逆数到生月所在宫位，再从该宫位顺数到生时，为正月所在宫位，之后每月一宫
   // 计算流月时需要考虑生月闰月情况，如果是后15天则计算时需要加1月
   const leapAddition = _birthday.isLeap && _birthday.lunarDay > 15 ? 1 : 0;
+  // 流月当月的闰月情况也需要考虑
+  const dateLeapAddition = _date.isLeap && _date.lunarDay > 15 ? 1 : 0;
   monthlyIndex = fixIndex(
     yearlyIndex -
       (_birthday.lunarMonth + leapAddition) +
       EARTHLY_BRANCHES.indexOf(kot<EarthlyBranchKey>($.rawDates.chineseDate.hourly[1])) +
-      _date.lunarMonth,
+      (_date.lunarMonth + dateLeapAddition),
   );
 
   // 获取流日索引
diff --git a/src/astro/astro.ts b/src/astro/astro.ts
index 81ce8ed..ce2b73d 100644
--- a/src/astro/astro.ts
+++ b/src/astro/astro.ts
@@ -229,6 +229,7 @@ export function bySolar<T extends FunctionalAstrolabe>(
 
   const chineseDate = getHeavenlyStemAndEarthlyBranchBySolarDate(solarDate, timeIndex, {
     year: getConfig().yearDivide,
+    month: getConfig().horoscopeDivide,
   });
   const lunarDate = solar2lunar(solarDate);
 
diff --git a/src/astro/palace.ts b/src/astro/palace.ts
index 6f4506f..5a6912b 100644
--- a/src/astro/palace.ts
+++ b/src/astro/palace.ts
@@ -43,6 +43,7 @@ export const getSoulAndBody = (param: AstrolabeParam): SoulAndBody => {
   const { solarDate, timeIndex, fixLeap, from } = param;
   const { yearly, hourly } = getHeavenlyStemAndEarthlyBranchBySolarDate(solarDate, timeIndex, {
     year: getConfig().yearDivide,
+    month: getConfig().horoscopeDivide,
   });
   const earthlyBranchOfTime = kot<EarthlyBranchKey>(hourly[1], 'Earthly');
   const heavenlyStemOfYear = kot<HeavenlyStemKey>(yearly[0], 'Heavenly');
diff --git a/yarn.lock b/yarn.lock
index eca06be..dd08c6b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3845,10 +3845,10 @@ lru-cache@^6.0.0:
   dependencies:
     yallist "^4.0.0"
 
-lunar-lite@^0.2.3:
-  version "0.2.3"
-  resolved "https://registry.npmjs.org/lunar-lite/-/lunar-lite-0.2.3.tgz#415274503dae18880ea0ad7db2c517468c89681a"
-  integrity sha512-sI8BMt3Q9RFvRJSKOdrutxRVc+REVmo709aeUKlAJFOg04+/PS9z/wORDVLJzo+fgBE7cdiIKGbNk1yU6emepg==
+lunar-lite@^0.2.7:
+  version "0.2.7"
+  resolved "https://registry.npmjs.org/lunar-lite/-/lunar-lite-0.2.7.tgz#3b68df72870627158acfa31d26d0f5fe9b441bbd"
+  integrity sha512-ePsbfKBUhnHINckdb5svyjSiYItxR6BySSmZ5Wjc5yRwKX8nbIVRBB0hwrW/NpZP5SuSXz1TSvuM/TVP9brZmw==
   dependencies:
     lunar-typescript "^1.7.5"
 



Test patch:
diff --git a/src/__tests__/astro/astro.test.ts b/src/__tests__/astro/astro.test.ts
index 46c347f..110a662 100644
--- a/src/__tests__/astro/astro.test.ts
+++ b/src/__tests__/astro/astro.test.ts
@@ -978,7 +978,7 @@ describe('Astrolabe', () => {
     expect(soulPalace?.decadal).toStrictEqual({ range: [6, 15], heavenlyStem: '丙', earthlyBranch: '寅' });
   });
 
-  test('withOptions() to fix GitHub#242', () => {
+  test('withOptions() to fix GitHub#242&#244', () => {
     astro.config({ yearDivide: 'normal' });
 
     const astrolable = withOptions({
@@ -991,5 +991,15 @@ describe('Astrolabe', () => {
 
     expect(horoscope.monthly).toHaveProperty('index', 7);
     expect(horoscope.daily).toHaveProperty('index', 9);
+
+    const horoscope2 = astrolable.horoscope('2020-6-6');
+
+    expect(horoscope2.monthly).toHaveProperty('index', 1);
+    expect(horoscope2.daily).toHaveProperty('index', 3);
+
+    const horoscope3 = astrolable.horoscope('2020-6-7');
+
+    expect(horoscope3.monthly).toHaveProperty('index', 2);
+    expect(horoscope3.daily).toHaveProperty('index', 5);
   });
 });