diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d62347b..2f7d5006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ - 🛠️ 修复(fix) - 🧹 琐事(Chore) +## v2.2.0 + +- 🪄 功能(feature) + + 🇨🇳 + + - 新增童限指示 #154 + + 🇺🇸 + + - add childhood scope indicator #154 + ## v2.1.0 - 🪄 功能(feature) diff --git a/src/__tests__/astro/astro.test.ts b/src/__tests__/astro/astro.test.ts index 8ba988a2..3249c9e0 100644 --- a/src/__tests__/astro/astro.test.ts +++ b/src/__tests__/astro/astro.test.ts @@ -691,4 +691,22 @@ describe('Astrolabe', () => { expect(getMajorStarByLunarDate('2023-2-17', 0, true)).toEqual('贪狼'); expect(getMajorStarByLunarDate('2023-2-17', 0, true, false)).toEqual('紫微,贪狼'); }); + + test('childhood', () => { + const astrolabe = astro.bySolar('2023-10-18', 4, 'female'); + const horo1 = astrolabe.horoscope('2023-12-19'); + + expect(horo1.decadal.name).toEqual('童限'); + expect(horo1.decadal.index).toEqual(astrolabe.palace('命宫')?.index); + + const horo2 = astrolabe.horoscope('2024-12-29'); + + expect(horo2.decadal.name).toEqual('童限'); + expect(horo2.decadal.index).toEqual(astrolabe.palace('财帛')?.index); + + const horo3 = astrolabe.horoscope('2025-12-29'); + + expect(horo3.decadal.name).toEqual('童限'); + expect(horo3.decadal.index).toEqual(astrolabe.palace('疾厄')?.index); + }); }); diff --git a/src/astro/FunctionalAstrolabe.ts b/src/astro/FunctionalAstrolabe.ts index 32bda5d4..2b75007f 100644 --- a/src/astro/FunctionalAstrolabe.ts +++ b/src/astro/FunctionalAstrolabe.ts @@ -37,13 +37,16 @@ const _getHoroscopeBySolarDate = ( timeIndex || convertTimeIndex, ); // 虚岁 - let nominalAge = Math.max(_date.lunarYear - _birthday.lunarYear, 1); + let nominalAge = _date.lunarYear - _birthday.lunarYear; + // 是否童限 + let isChildhood = false; // 假如目标日期已经过了生日,则需要加1岁 // 比如 2022年九月初一 出生的人,在出生后虚岁为 1 岁 // 但在 2023年九月初二 以后,虚岁则为 2 岁 if ( - (_date.lunarMonth === _birthday.lunarMonth && _date.lunarDay > _birthday.lunarDay) || + ((_date.lunarYear === _birthday.lunarYear && _date.lunarMonth) === _birthday.lunarMonth && + _date.lunarDay > _birthday.lunarDay) || _date.lunarMonth > _birthday.lunarMonth ) { nominalAge += 1; @@ -77,6 +80,23 @@ const _getHoroscopeBySolarDate = ( } }); + if (decadalIndex < 0) { + // 如果大限索引小于0则证明还没有开始起运 + // 此时应该取小限运 + // 一命二财三疾厄 四岁夫妻五福德 + // 六岁事业为童限 专就宫垣视吉凶 + const palaces: PalaceName[] = ['命宫', '财帛', '疾厄', '夫妻', '福德', '官禄']; + const targetIndex = palaces[nominalAge - 1]; + const targetPalace = $.palace(targetIndex); + + if (targetPalace) { + isChildhood = true; + decadalIndex = targetPalace.index; + heavenlyStemOfDecade = targetPalace.heavenlyStem; + earthlyBranchOfDecade = targetPalace.earthlyBranch; + } + } + // 查询小限索引 $.palaces.some(({ ages }, index) => { if (ages.includes(nominalAge)) { @@ -105,7 +125,7 @@ const _getHoroscopeBySolarDate = ( lunarDate: _date.toString(true), decadal: { index: decadalIndex, - name: t('decadal'), + name: isChildhood ? t('childhood') : t('decadal'), heavenlyStem: t(kot(heavenlyStemOfDecade, 'Heavnly')), earthlyBranch: t(kot(earthlyBranchOfDecade, 'Earthly')), palaceNames: getPalaceNames(decadalIndex), diff --git a/src/astro/FunctionalPalace.ts b/src/astro/FunctionalPalace.ts index 0f267fb7..eadc9e7d 100644 --- a/src/astro/FunctionalPalace.ts +++ b/src/astro/FunctionalPalace.ts @@ -180,6 +180,7 @@ export interface IFunctionalPalace extends Palace { */ export default class FunctionalPalace implements IFunctionalPalace { private _astrolabe?: IFunctionalAstrolabe; + index; name; isBodyPalace; isOriginalPalace; @@ -196,6 +197,7 @@ export default class FunctionalPalace implements IFunctionalPalace { ages; constructor(data: Palace) { + this.index = data.index; this.name = data.name; this.isBodyPalace = data.isBodyPalace; this.isOriginalPalace = data.isOriginalPalace; diff --git a/src/astro/astro.ts b/src/astro/astro.ts index 0c9b57bd..2e2bd48f 100644 --- a/src/astro/astro.ts +++ b/src/astro/astro.ts @@ -82,6 +82,7 @@ export const bySolar = ( palaces.push( new FunctionalPalace({ + index: i, name: palaceNames[i], isBodyPalace: bodyIndex === i, isOriginalPalace: diff --git a/src/data/types/palace.ts b/src/data/types/palace.ts index 4c138707..4cae67b0 100644 --- a/src/data/types/palace.ts +++ b/src/data/types/palace.ts @@ -43,6 +43,8 @@ export type SoulAndBody = { * - ages 小限 */ export type Palace = { + /** 宫位索引 */ + index: number; /** 宫位名称 */ name: PalaceName; /** 是否身宫 */ diff --git a/src/i18n/locales/ja-JP/common.json b/src/i18n/locales/ja-JP/common.json index 85a44128..e944c80e 100644 --- a/src/i18n/locales/ja-JP/common.json +++ b/src/i18n/locales/ja-JP/common.json @@ -1,5 +1,6 @@ { "decadal": "大限", + "childhood": "子供", "yearly": "流年", "monthly": "流月", "daily": "流日", diff --git a/src/i18n/locales/ko-KR/common.json b/src/i18n/locales/ko-KR/common.json index 4859c5b1..e9c1e5d5 100644 --- a/src/i18n/locales/ko-KR/common.json +++ b/src/i18n/locales/ko-KR/common.json @@ -1,5 +1,6 @@ { "decadal": "대한", + "childhood": "어린", "yearly": "유년", "monthly": "유월", "daily": "유일", diff --git a/src/i18n/locales/vi-VN/common.json b/src/i18n/locales/vi-VN/common.json index 556d80a5..a5a19b13 100644 --- a/src/i18n/locales/vi-VN/common.json +++ b/src/i18n/locales/vi-VN/common.json @@ -1,5 +1,6 @@ { "decadal": "Đại Hạn", + "childhood": "đứa trẻ Hạn", "yearly": "Lưu Niên", "monthly": "Lưu Nguyệt", "daily": "Lưu Nhật", diff --git a/src/i18n/locales/zh-CN/common.json b/src/i18n/locales/zh-CN/common.json index 4b4c509a..f0a1af39 100644 --- a/src/i18n/locales/zh-CN/common.json +++ b/src/i18n/locales/zh-CN/common.json @@ -1,5 +1,6 @@ { "decadal": "大限", + "childhood": "童限", "yearly": "流年", "monthly": "流月", "daily": "流日", diff --git a/src/i18n/locales/zh-TW/common.json b/src/i18n/locales/zh-TW/common.json index b08fa405..6361d193 100644 --- a/src/i18n/locales/zh-TW/common.json +++ b/src/i18n/locales/zh-TW/common.json @@ -1,5 +1,6 @@ { "decadal": "大限", + "childhood": "童限", "yearly": "流年", "monthly": "流月", "daily": "流日",