Skip to content

Commit

Permalink
v1.1.0 更改了getYear()、getMonth()、getDay()的返回类型,非兼容性更新;新增吉神宜趋、凶神宜忌;新增每日宜…
Browse files Browse the repository at this point in the history
…忌、时辰宜忌;修复:农历日获取时辰列表遇闰月报错的问题。
  • Loading branch information
6tail committed Jul 9, 2024
1 parent 91d8f6f commit a9a3fbc
Show file tree
Hide file tree
Showing 9 changed files with 571 additions and 182 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
2. 新增:六曜。
3. 新增:入梅出梅。
4. 新增:获取农历日当天的时辰列表。

## [1.1.0] - 2024-07-09
1. 注意:此版本更改了getYear()、getMonth()、getDay()的返回类型,非兼容性更新。
2. 新增:吉神宜趋、凶神宜忌。
3. 新增:每日宜忌、时辰宜忌。
4. 修复:农历日获取时辰列表遇闰月报错的问题。
514 changes: 363 additions & 151 deletions lib/index.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tyme4ts",
"version": "1.0.7",
"version": "1.1.0",
"description": "Tyme是一个非常强大的日历工具库,可以看作 Lunar 的升级版,拥有更优的设计和扩展性,支持公历和农历、星座、干支、生肖、节气、法定假日等。",
"main": "./dist/lib/index.cjs",
"module": "./dist/lib/index.mjs",
Expand Down
8 changes: 4 additions & 4 deletions test/EightCharTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ class EightCharTest {
// 童限结束(即开始起运)的公历时刻
equal(childLimit.getEndTime().toString(), '1989年5月4日 18:24:00');
// 童限开始(即出生)的农历年干支
equal(childLimit.getStartTime().getLunarHour().getDay().getMonth().getYear().getSixtyCycle().getName(), '癸亥');
equal(childLimit.getStartTime().getLunarHour().getLunarDay().getLunarMonth().getLunarYear().getSixtyCycle().getName(), '癸亥');
// 童限结束(即开始起运)的农历年干支
equal(childLimit.getEndTime().getLunarHour().getDay().getMonth().getYear().getSixtyCycle().getName(), '己巳');
equal(childLimit.getEndTime().getLunarHour().getLunarDay().getLunarMonth().getLunarYear().getSixtyCycle().getName(), '己巳');

// 第1轮大运
const decadeFortune = childLimit.getStartDecadeFortune();
Expand Down Expand Up @@ -323,9 +323,9 @@ class EightCharTest {
// 童限结束(即开始起运)的公历时刻
equal(childLimit.getEndTime().toString(), '2001年2月11日 18:58:00');
// 童限开始(即出生)的农历年干支
equal(childLimit.getStartTime().getLunarHour().getDay().getMonth().getYear().getSixtyCycle().getName(), '辛未');
equal(childLimit.getStartTime().getLunarHour().getLunarDay().getLunarMonth().getLunarYear().getSixtyCycle().getName(), '辛未');
// 童限结束(即开始起运)的农历年干支
equal(childLimit.getEndTime().getLunarHour().getDay().getMonth().getYear().getSixtyCycle().getName(), '辛巳');
equal(childLimit.getEndTime().getLunarHour().getLunarDay().getLunarMonth().getLunarYear().getSixtyCycle().getName(), '辛巳');

// 第1轮大运
const decadeFortune = childLimit.getStartDecadeFortune();
Expand Down
94 changes: 94 additions & 0 deletions test/GodTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {suite, test} from '@testdeck/mocha';
import {God, LunarDay, SolarDay} from '../lib';
import {deepEqual} from 'assert';

@suite
class GodTest {
@test
test0() {
const lunar: LunarDay = SolarDay.fromYmd(2004, 2, 16).getLunarDay();
const gods: God[] = lunar.getGods();
const ji: string[] = [];
gods.forEach(god => {
if ('吉' == god.getLuck().getName()) {
ji.push(god.getName());
}
});

const xiong: string[] = [];
gods.forEach(god => {
if ('凶' == god.getLuck().getName()) {
xiong.push(god.getName());
}
});

deepEqual(ji, ['天恩', '续世', '明堂']);
deepEqual(xiong, ['月煞', '月虚', '血支', '天贼', '五虚', '土符', '归忌', '血忌']);
}

@test
test1() {
const lunar: LunarDay = SolarDay.fromYmd(2029, 11, 16).getLunarDay();
const gods: God[] = lunar.getGods();
const ji: string[] = [];
gods.forEach(god => {
if ('吉' == god.getLuck().getName()) {
ji.push(god.getName());
}
});

const xiong: string[] = [];
gods.forEach(god => {
if ('凶' == god.getLuck().getName()) {
xiong.push(god.getName());
}
});

deepEqual(ji, ['天德合', '月空', '天恩', '益后', '金匮']);
deepEqual(xiong, ['月煞', '月虚', '血支', '五虚']);
}

@test
test2() {
const lunar: LunarDay = SolarDay.fromYmd(1954, 7, 16).getLunarDay();
const gods: God[] = lunar.getGods();
const ji: string[] = [];
gods.forEach(god => {
if ('吉' == god.getLuck().getName()) {
ji.push(god.getName());
}
});

const xiong: string[] = [];
gods.forEach(god => {
if ('凶' == god.getLuck().getName()) {
xiong.push(god.getName());
}
});

deepEqual(ji, ['民日', '天巫', '福德', '天仓', '不将', '续世', '除神', '鸣吠']);
deepEqual(xiong, ['劫煞', '天贼', '五虚', '五离']);
}

@test
test3() {
const lunar: LunarDay = SolarDay.fromYmd(2024, 12, 27).getLunarDay();
const gods: God[] = lunar.getGods();
const ji: string[] = [];
gods.forEach(god => {
if ('吉' == god.getLuck().getName()) {
ji.push(god.getName());
}
});

const xiong: string[] = [];
gods.forEach(god => {
if ('凶' == god.getLuck().getName()) {
xiong.push(god.getName());
}
});

deepEqual(ji, ['天恩', '四相', '阴德', '守日', '吉期', '六合', '普护', '宝光']);
deepEqual(xiong, ['三丧', '鬼哭']);
}
}
8 changes: 4 additions & 4 deletions test/LunarDayTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ class LunarDayTest {

@test
test22() {
equal(LunarDay.fromYmd(2024, 1, 1).getMonth().getYear().getSixtyCycle().getName(), '甲辰');
equal(LunarDay.fromYmd(2024, 1, 1).getLunarMonth().getLunarYear().getSixtyCycle().getName(), '甲辰');
}

@test
test23() {
equal(LunarDay.fromYmd(2023, 12, 30).getMonth().getYear().getSixtyCycle().getName(), '癸卯');
equal(LunarDay.fromYmd(2023, 12, 30).getLunarMonth().getLunarYear().getSixtyCycle().getName(), '癸卯');
}

/**
Expand Down Expand Up @@ -152,8 +152,8 @@ class LunarDayTest {

@test
test26() {
const lunar = LunarDay.fromYmd(2005, 11, 23);
equal(lunar.getMonth().getSixtyCycle().getName(), '戊子');
const lunar: LunarDay = LunarDay.fromYmd(2005, 11, 23);
equal(lunar.getLunarMonth().getSixtyCycle().getName(), '戊子');
equal(lunar.getMonthSixtyCycle().getName(), '戊子');
}
}
40 changes: 20 additions & 20 deletions test/LunarMonthTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,44 +154,44 @@ class LunarMonthTest {

@test
test29() {
const d = SolarDay.fromYmd(2023, 10, 7).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '壬戌');
const d: LunarDay = SolarDay.fromYmd(2023, 10, 7).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '壬戌');
equal(d.getMonthSixtyCycle().toString(), '辛酉');
}

@test
test30() {
const d = SolarDay.fromYmd(2023, 10, 8).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '壬戌');
const d: LunarDay = SolarDay.fromYmd(2023, 10, 8).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '壬戌');
equal(d.getMonthSixtyCycle().toString(), '壬戌');
}

@test
test31() {
const d = SolarDay.fromYmd(2023, 10, 15).getLunarDay();
equal(d.getMonth().getName(), '九月');
equal(d.getMonth().getSixtyCycle().toString(), '癸亥');
const d: LunarDay = SolarDay.fromYmd(2023, 10, 15).getLunarDay();
equal(d.getLunarMonth().getName(), '九月');
equal(d.getLunarMonth().getSixtyCycle().toString(), '癸亥');
equal(d.getMonthSixtyCycle().toString(), '壬戌');
}

@test
test32() {
const d = SolarDay.fromYmd(2023, 11, 7).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '癸亥');
const d: LunarDay = SolarDay.fromYmd(2023, 11, 7).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '癸亥');
equal(d.getMonthSixtyCycle().toString(), '壬戌');
}

@test
test33() {
const d = SolarDay.fromYmd(2023, 11, 8).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '癸亥');
const d: LunarDay = SolarDay.fromYmd(2023, 11, 8).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '癸亥');
equal(d.getMonthSixtyCycle().toString(), '癸亥');
}

@test
test34() {
// 2023年闰2月
const m = LunarMonth.fromYm(2023, 12);
const m: LunarMonth = LunarMonth.fromYm(2023, 12);
equal(m.toString(), '农历癸卯年十二月');
equal(m.next(-1).toString(), '农历癸卯年十一月');
equal(m.next(-2).toString(), '农历癸卯年十月');
Expand All @@ -200,7 +200,7 @@ class LunarMonthTest {
@test
test35() {
// 2023年闰2月
const m = LunarMonth.fromYm(2023, 3);
const m: LunarMonth = LunarMonth.fromYm(2023, 3);
equal(m.toString(), '农历癸卯年三月');
equal(m.next(-1).toString(), '农历癸卯年闰二月');
equal(m.next(-2).toString(), '农历癸卯年二月');
Expand All @@ -211,28 +211,28 @@ class LunarMonthTest {

@test
test36() {
const d = SolarDay.fromYmd(1983, 2, 15).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '甲寅');
const d: LunarDay = SolarDay.fromYmd(1983, 2, 15).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '甲寅');
equal(d.getMonthSixtyCycle().toString(), '甲寅');
}

@test
test37() {
const d = SolarDay.fromYmd(2023, 10, 30).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '癸亥');
const d: LunarDay = SolarDay.fromYmd(2023, 10, 30).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '癸亥');
equal(d.getMonthSixtyCycle().toString(), '壬戌');
}

@test
test38() {
const d = SolarDay.fromYmd(2023, 10, 19).getLunarDay();
equal(d.getMonth().getSixtyCycle().toString(), '癸亥');
const d: LunarDay = SolarDay.fromYmd(2023, 10, 19).getLunarDay();
equal(d.getLunarMonth().getSixtyCycle().toString(), '癸亥');
equal(d.getMonthSixtyCycle().toString(), '壬戌');
}

@test
test39() {
const m = LunarMonth.fromYm(2023, 11);
const m: LunarMonth = LunarMonth.fromYm(2023, 11);
equal(m.toString(), '农历癸卯年十一月');
equal(m.getSixtyCycle().toString(), '乙丑');
}
Expand Down
4 changes: 2 additions & 2 deletions test/SolarDayTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class SolarDayTest {

@test
test22() {
equal('甲辰', SolarDay.fromYmd(2024, 2, 10).getLunarDay().getMonth().getYear().getSixtyCycle().getName());
equal('甲辰', SolarDay.fromYmd(2024, 2, 10).getLunarDay().getLunarMonth().getLunarYear().getSixtyCycle().getName());
}

@test
test23() {
equal('癸卯', SolarDay.fromYmd(2024, 2, 9).getLunarDay().getMonth().getYear().getSixtyCycle().getName());
equal('癸卯', SolarDay.fromYmd(2024, 2, 9).getLunarDay().getLunarMonth().getLunarYear().getSixtyCycle().getName());
}
}
77 changes: 77 additions & 0 deletions test/TabooTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {suite, test} from '@testdeck/mocha';
import {SolarDay, SolarTime} from '../lib';
import {deepEqual} from 'assert';

@suite
class TabooTest {
@test
test0() {
const taboos: string[] = [];
SolarDay.fromYmd(2024, 6, 26).getLunarDay().getRecommends().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, ['嫁娶', '祭祀', '理发', '作灶', '修饰垣墙', '平治道涂', '整手足甲', '沐浴', '冠笄']);
}

@test
test1() {
const taboos: string[] = [];
SolarDay.fromYmd(2024, 6, 26).getLunarDay().getAvoids().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, ['破土', '出行', '栽种']);
}

@test
test2() {
const taboos: string[] = [];
SolarTime.fromYmdHms(2024, 6, 25, 4, 0, 0).getLunarHour().getRecommends().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, []);
}

@test
test3() {
const taboos: string[] = [];
SolarTime.fromYmdHms(2024, 6, 25, 4, 0, 0).getLunarHour().getAvoids().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, ['诸事不宜']);
}

@test
test4() {
const taboos: string[] = [];
SolarTime.fromYmdHms(2024, 4, 22, 0, 0, 0).getLunarHour().getRecommends().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, ['嫁娶', '交易', '开市', '安床', '祭祀', '求财']);
}

@test
test5() {
const taboos: string[] = [];
SolarTime.fromYmdHms(2024, 4, 22, 0, 0, 0).getLunarHour().getAvoids().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, ['出行', '移徙', '赴任', '词讼', '祈福', '修造', '求嗣']);
}

@test
test6() {
const taboos: string[] = [];
SolarDay.fromYmd(2021, 3, 7).getLunarDay().getRecommends().forEach(t => {
taboos.push(t.getName());
});

deepEqual(taboos, ['裁衣', '经络', '伐木', '开柱眼', '拆卸', '修造', '动土', '上梁', '合脊', '合寿木', '入殓', '除服', '成服', '移柩', '破土', '安葬', '启钻', '修坟', '立碑']);
}

}

0 comments on commit a9a3fbc

Please sign in to comment.