Skip to content

Commit e9ade61

Browse files
authored
Merge pull request #191 from SylarLong/fix/190
🛠️ Wrong results using the parameter yearDivide to 'normal'.
2 parents 214bab2 + 6c80375 commit e9ade61

File tree

9 files changed

+103
-20
lines changed

9 files changed

+103
-20
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
- 🛠️ 修复(fix)
88
- 🧹 琐事(Chore)
99

10+
## v2.4.3
11+
12+
- 🛠️ 修复(fix)
13+
14+
🇨🇳
15+
16+
- 新增运限分界点参数以满足不同需求 #190
17+
18+
🇺🇸
19+
20+
- Wrong results using the parameter yearDivide to 'normal'. #190
21+
1022
## v2.4.2
1123

1224
- 🛠️ 修复(fix)

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iztro",
3-
"version": "2.4.2",
3+
"version": "2.4.3",
44
"description": "轻量级紫微斗数星盘生成库。可以通过出生年月日获取到紫微斗数星盘信息、生肖、星座等信息。A lightweight kit to astrolabe generator of The Purple Star Astrology (Zi Wei Dou Shu). The Purple Star Astrology(Zi Wei Dou Shu) is a Chinese ancient astrology. You're able to get your horoscope and personality from the astrolabe",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -71,6 +71,6 @@
7171
"dependencies": {
7272
"dayjs": "^1.11.10",
7373
"i18next": "^23.5.1",
74-
"lunar-lite": "^0.2.0"
74+
"lunar-lite": "^0.2.3"
7575
}
7676
}

src/__tests__/astro/astro.test.ts

+63
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,20 @@ describe('Astrolabe', () => {
648648
expect(horoscope.yearly).toHaveProperty('heavenlyStem', '庚');
649649
});
650650

651+
test('check special date `1995-3-30`', () => {
652+
astro.config({ yearDivide: 'normal' });
653+
654+
const result = astro.bySolar('1995-03-30', 0, 'male', true);
655+
656+
expect(result).toHaveProperty('solarDate', '1995-03-30');
657+
expect(result).toHaveProperty('lunarDate', '一九九五年二月三十');
658+
659+
const result2 = astro.byLunar('1995-2-30', 0, 'male', true);
660+
661+
expect(result2).toHaveProperty('solarDate', '1995-3-30');
662+
expect(result2).toHaveProperty('lunarDate', '一九九五年二月三十');
663+
});
664+
651665
test('withOptions()', () => {
652666
const result = astro.withOptions({
653667
type: 'lunar',
@@ -700,6 +714,55 @@ describe('Astrolabe', () => {
700714
expect(result).toHaveProperty('fiveElementsClass', '土五局');
701715
});
702716

717+
test('withOptions() 3', () => {
718+
const result = astro.withOptions({
719+
type: 'lunar',
720+
dateStr: '1979-12-28',
721+
timeIndex: 0,
722+
gender: 'female',
723+
isLeapMonth: false,
724+
fixLeap: true,
725+
language: 'zh-CN',
726+
config: {
727+
yearDivide: 'normal',
728+
horoscopeDivide: 'normal',
729+
},
730+
});
731+
732+
expect(result).toHaveProperty('solarDate', '1980-2-14');
733+
expect(result).toHaveProperty('lunarDate', '一九七九年腊月廿八');
734+
expect(result).toHaveProperty('chineseDate', '己未 戊寅 丁巳 庚子');
735+
expect(result).toHaveProperty('time', '早子时');
736+
expect(result).toHaveProperty('zodiac', '羊');
737+
expect(result).toHaveProperty('earthlyBranchOfSoulPalace', '丑');
738+
expect(result).toHaveProperty('earthlyBranchOfBodyPalace', '丑');
739+
expect(result).toHaveProperty('soul', '巨门');
740+
expect(result).toHaveProperty('body', '天相');
741+
expect(result).toHaveProperty('fiveElementsClass', '水二局');
742+
743+
const horoscope = result.horoscope('1980-2-14');
744+
745+
expect(horoscope.yearly.earthlyBranch).toBe('未');
746+
747+
const result2 = astro.withOptions({
748+
type: 'lunar',
749+
dateStr: '1979-12-28',
750+
timeIndex: 0,
751+
gender: 'female',
752+
isLeapMonth: false,
753+
fixLeap: true,
754+
language: 'zh-CN',
755+
config: {
756+
yearDivide: 'normal',
757+
horoscopeDivide: 'exact',
758+
},
759+
});
760+
761+
const horoscope2 = result2.horoscope('1980-2-14');
762+
763+
expect(horoscope2.yearly.earthlyBranch).toBe('申');
764+
});
765+
703766
test('bySolar() fix leap month', () => {
704767
const result = astro.bySolar('2023-4-10', 4, '女', true);
705768

src/astro/FunctionalAstrolabe.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IFunctionalPalace } from './FunctionalPalace';
1111
import { IFunctionalSurpalaces } from './FunctionalSurpalaces';
1212
import { getPalaceNames } from './palace';
1313
import FunctionalHoroscope, { IFunctionalHoroscope } from './FunctionalHoroscope';
14+
import { getConfig } from './astro';
1415

1516
/**
1617
* 获取运限数据
@@ -36,8 +37,8 @@ const _getHoroscopeBySolarDate = (
3637
targetDate,
3738
timeIndex || convertTimeIndex,
3839
{
39-
// 运限是以立春为界
40-
year: 'exact',
40+
// 运限是以立春为界,但为了满足部分流派允许配置
41+
year: getConfig().horoscopeDivide,
4142
},
4243
);
4344
// 虚岁

src/astro/astro.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const _brightness: Partial<Record<StarKey, BrightnessKey[]>> = {};
3131
* exact:立春分界
3232
*/
3333
let _yearDivide: 'normal' | 'exact' = 'exact';
34+
let _horoscopeDivide: 'normal' | 'exact' = 'exact';
3435

3536
/**
3637
* 批量加载插件
@@ -64,7 +65,7 @@ export const loadPlugin = (plugin: Plugin) => {
6465
*
6566
* @param {Config} param0 自定义配置
6667
*/
67-
export const config = ({ mutagens, brightness, yearDivide }: Config) => {
68+
export const config = ({ mutagens, brightness, yearDivide, horoscopeDivide }: Config) => {
6869
if (mutagens) {
6970
Object.entries(mutagens).forEach(([key, value]) => {
7071
_mutagens[kot<HeavenlyStemKey>(key)] = value.map((item) => kot<StarKey>(item)) ?? [];
@@ -80,12 +81,17 @@ export const config = ({ mutagens, brightness, yearDivide }: Config) => {
8081
if (yearDivide) {
8182
_yearDivide = yearDivide;
8283
}
84+
85+
if (horoscopeDivide) {
86+
_horoscopeDivide = horoscopeDivide;
87+
}
8388
};
8489

8590
export const getConfig = () => ({
8691
mutagens: _mutagens,
8792
brightness: _brightness,
8893
yearDivide: _yearDivide,
94+
horoscopeDivide: _horoscopeDivide,
8995
});
9096

9197
/**

src/data/types/astro.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ export type Config = {
174174
mutagens?: ConfigMutagens;
175175
brightness?: ConfigBrightness;
176176
yearDivide?: 'normal' | 'exact';
177+
horoscopeDivide?: 'normal' | 'exact';
177178
};
178-
179+
179180
export type Option = {
180181
type: 'solar' | 'lunar';
181182
dateStr: string;

src/star/decorativeStar.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export const getYearly12 = (solarDateStr: string | Date): { suiqian12: StarName[
211211
const jiangqian12: StarName[] = [];
212212
const suiqian12: StarName[] = [];
213213
const { yearly } = getHeavenlyStemAndEarthlyBranchBySolarDate(solarDateStr, 0, {
214-
// 流年神煞应该用立春为界
215-
year: 'exact',
214+
// 流年神煞应该用立春为界,但为了满足不同流派的需求允许配置
215+
year: getConfig().horoscopeDivide,
216216
});
217217

218218
const ts12shen: StarKey[] = [

src/star/location.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getHeavenlyStemAndEarthlyBranchBySolarDate, getTotalDaysOfLunarMonth, solar2lunar } from 'lunar-lite';
2-
import { getFiveElementsClass, getSoulAndBody } from '../astro';
2+
import { getConfig, getFiveElementsClass, getSoulAndBody } from '../astro';
33
import { EARTHLY_BRANCHES, FiveElementsClass, HEAVENLY_STEMS, PALACES } from '../data';
44
import {
55
EarthlyBranchKey,
@@ -561,8 +561,8 @@ export const getGuGuaIndex = (earthlyBranchName: EarthlyBranchName) => {
561561
*/
562562
export const getYearlyStarIndex = (solarDate: string, timeIndex: number, fixLeap?: boolean) => {
563563
const { yearly } = getHeavenlyStemAndEarthlyBranchBySolarDate(solarDate, timeIndex, {
564-
// 流耀应该用立春为界
565-
year: 'exact',
564+
// 流耀应该用立春为界,但为了满足不同流派的需求允许配置
565+
year: getConfig().horoscopeDivide,
566566
});
567567
const { soulIndex, bodyIndex } = getSoulAndBody(solarDate, timeIndex, fixLeap);
568568
const heavenlyStem = kot<HeavenlyStemKey>(yearly[0], 'Heavenly');

yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -3870,17 +3870,17 @@ lru-cache@^6.0.0:
38703870
dependencies:
38713871
yallist "^4.0.0"
38723872

3873-
lunar-lite@^0.2.0:
3874-
version "0.2.0"
3875-
resolved "https://registry.npmjs.org/lunar-lite/-/lunar-lite-0.2.0.tgz#12214860bb753b0840aaf553ae3754b4c4998af1"
3876-
integrity sha512-Dskql5YCpd6xjtXj3Rl61A1qxT0zaPdold/tM/n6m0r7bfZ6FfEFom7zzKPJMuD0XUNji5C/ItuaMR+LAjqAVQ==
3873+
lunar-lite@^0.2.3:
3874+
version "0.2.3"
3875+
resolved "https://registry.npmjs.org/lunar-lite/-/lunar-lite-0.2.3.tgz#415274503dae18880ea0ad7db2c517468c89681a"
3876+
integrity sha512-sI8BMt3Q9RFvRJSKOdrutxRVc+REVmo709aeUKlAJFOg04+/PS9z/wORDVLJzo+fgBE7cdiIKGbNk1yU6emepg==
38773877
dependencies:
3878-
lunar-typescript "^1.7.3"
3878+
lunar-typescript "^1.7.5"
38793879

3880-
lunar-typescript@^1.7.3:
3881-
version "1.7.3"
3882-
resolved "https://registry.npmjs.org/lunar-typescript/-/lunar-typescript-1.7.3.tgz#841d997687a0145a1fe9f65db735675f66d06660"
3883-
integrity sha512-VXMdgh2Psrn3vtfrai4lPug3Mt7ijYGVTICDARA8tLzqGv3Io/OvS23wxzFi/AbSzxt93u2wWhgv3VGKPSbUgQ==
3880+
lunar-typescript@^1.7.5:
3881+
version "1.7.5"
3882+
resolved "https://registry.npmjs.org/lunar-typescript/-/lunar-typescript-1.7.5.tgz#8a407f9db10aaf896f1477564dbfef741463e245"
3883+
integrity sha512-AlOwYrxHRCR9Plba5TlZY0NVv6aFobmR1gxfiAE1KxjDzBXoDtT2KrsBYCVaErGokiL8qLMS1FNwGPiPRX2a4g==
38843884

38853885
make-dir@^4.0.0:
38863886
version "4.0.0"

0 commit comments

Comments
 (0)