Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪄 add childhood scope indicator #156

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
- 🛠️ 修复(fix)
- 🧹 琐事(Chore)

## v2.2.0

- 🪄 功能(feature)

🇨🇳

- 新增童限指示 #154

🇺🇸

- add childhood scope indicator #154

## v2.1.0

- 🪄 功能(feature)
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/astro/astro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
26 changes: 23 additions & 3 deletions src/astro/FunctionalAstrolabe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/astro/FunctionalPalace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export interface IFunctionalPalace extends Palace {
*/
export default class FunctionalPalace implements IFunctionalPalace {
private _astrolabe?: IFunctionalAstrolabe;
index;
name;
isBodyPalace;
isOriginalPalace;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/astro/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const bySolar = (

palaces.push(
new FunctionalPalace({
index: i,
name: palaceNames[i],
isBodyPalace: bodyIndex === i,
isOriginalPalace:
Expand Down
2 changes: 2 additions & 0 deletions src/data/types/palace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export type SoulAndBody = {
* - ages 小限
*/
export type Palace = {
/** 宫位索引 */
index: number;
/** 宫位名称 */
name: PalaceName;
/** 是否身宫 */
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ja-JP/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"decadal": "大限",
"childhood": "子供",
"yearly": "流年",
"monthly": "流月",
"daily": "流日",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ko-KR/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"decadal": "대한",
"childhood": "어린",
"yearly": "유년",
"monthly": "유월",
"daily": "유일",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/vi-VN/common.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/zh-CN/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"decadal": "大限",
"childhood": "童限",
"yearly": "流年",
"monthly": "流月",
"daily": "流日",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/zh-TW/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"decadal": "大限",
"childhood": "童限",
"yearly": "流年",
"monthly": "流月",
"daily": "流日",
Expand Down
Loading