1
0
mirror of synced 2026-04-15 21:08:40 +08:00

Compare commits

...

6 Commits

11 changed files with 289 additions and 64 deletions

View File

@@ -147,3 +147,24 @@ test('身宫', () => {
const eightChar = lunar.getEightChar();
expect(eightChar.getShenGong()).toBe('壬午');
});
test('身宫1', () => {
const solar = Solar.fromYmdHms(1994, 12, 6, 2, 0, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getShenGong()).toBe('丁丑');
});
test('身宫2', () => {
const solar = Solar.fromYmdHms(1990, 12, 11, 6, 0, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getShenGong()).toBe('庚辰');
});
test('身宫3', () => {
const solar = Solar.fromYmdHms(1993, 5, 23, 4, 0, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getShenGong()).toBe('庚申');
});

View File

@@ -1,4 +1,4 @@
var {HolidayUtil} = require('../lunar');
const {HolidayUtil} = require('../lunar');
test('test1', () => {
expect(HolidayUtil.getHoliday('2020-01-01') + '').toBe('2020-01-01 元旦节 2020-01-01');
@@ -42,3 +42,12 @@ test('test1', () => {
test('test2', () => {
expect(HolidayUtil.getHoliday('2016-10-04').getTarget()).toBe('2016-10-01');
});
test('testRemove', () => {
let holiday = HolidayUtil.getHoliday('2010-01-01');
expect(holiday.getName()).toBe('元旦');
HolidayUtil.fix('20100101~000000000000000000000000000');
holiday = HolidayUtil.getHoliday('2010-01-01');
expect(holiday).toBe(null);
});

View File

@@ -570,3 +570,23 @@ test('test052', () => {
const lunar = Solar.fromYmd(2011, 11, 12).getLunar();
expect(lunar.getDayPositionTai()).toBe('厕灶厨 外西南');
});
test('test053', () => {
const lunar = Solar.fromYmd(1722, 9, 25).getLunar();
expect(lunar.getOtherFestivals() + '').toBe('秋社');
});
test('test054', () => {
const lunar = Solar.fromYmd(840, 9, 14).getLunar();
expect(lunar.getOtherFestivals() + '').toBe('秋社');
});
test('test055', () => {
const lunar = Solar.fromYmd(2022, 3, 16).getLunar();
expect(lunar.getOtherFestivals() + '').toBe('春社');
});
test('test056', () => {
const lunar = Solar.fromYmd(2021, 3, 21).getLunar();
expect(lunar.getOtherFestivals() + '').toBe('春社');
});

View File

@@ -87,3 +87,8 @@ test('test17', () => {
const year = LunarYear.fromYear(2004);
expect(year.getYun()).toBe('八运');
});
test('test18', () => {
const year = LunarYear.fromYear(2022);
expect(year.getJieQiJulianDays()).toStrictEqual([2459555.7478605337, 2459570.499405936, 2459585.217980813, 2459599.9437018055, 2459614.7018054826, 2459629.5297495862, 2459644.446920318, 2459659.4814200983, 2459674.6389274267, 2459689.9334118855, 2459705.3512322665, 2459720.890569021, 2459736.517794922, 2459752.2178259823, 2459767.9429320656, 2459783.6713957503, 2459799.3534378354, 2459814.969435438, 2459830.480632029, 2459845.8774438635, 2459861.140466851, 2459876.2746654437, 2459891.281458942, 2459906.1807667296, 2459920.9903281447, 2459935.741672728, 2459950.461561025, 2459965.187040542, 2459979.9460747372, 2459994.7736723446, 2460009.6916930582]);
});

View File

@@ -31,3 +31,28 @@ test('9', () => {
test('10', () => {
expect(SolarUtil.isLeapYear(1500)).toBe(false);
});
test('11', () => {
var solar = Solar.fromYmd(2022, 3, 28);
expect(solar.getFestivals() + '').toBe('全国中小学生安全教育日');
});
test('12', () => {
var solar = Solar.fromYmd(2021, 3, 29);
expect(solar.getFestivals() + '').toBe('全国中小学生安全教育日');
});
test('13', () => {
var solar = Solar.fromYmd(1996, 3, 25);
expect(solar.getFestivals() + '').toBe('全国中小学生安全教育日');
});
test('14', () => {
const solar = Solar.fromYmd(1583, 1, 13);
expect(solar.getLunar().toString()).toBe('一五八二年腊月二十');
});
test('15', () => {
const solar = Solar.fromYmd(1583, 1, 14);
expect(solar.getLunar().toString()).toBe('一五八二年腊月廿一');
});

View File

@@ -1,13 +1,37 @@
var {SolarSeason} = require('../lunar');
var {SolarMonth} = require('../lunar');
test('toString()', () => {
const season = SolarSeason.fromYm(2019, 5);
expect(season.toString()).toBe('2019.2');
expect(season.next(1).toString()).toBe('2019.3');
const month = SolarMonth.fromYm(2019, 5);
expect(month.toString()).toBe('2019-5');
expect(month.next(1).toString()).toBe('2019-6');
});
test('toFullString()', () => {
const season = SolarSeason.fromYm(2019, 5);
expect(season.toFullString()).toBe('2019年2季度');
expect(season.next(1).toFullString()).toBe('2019年3季度');
const month = SolarMonth.fromYm(2019, 5);
expect(month.toFullString()).toBe('2019年5月');
expect(month.next(1).toFullString()).toBe('2019年6月');
});
test('test1', () => {
const month = SolarMonth.fromYm(2022, 7);
const weeks = month.getWeeks(0);
const lastWeek = weeks[weeks.length - 1];
const days = lastWeek.getDays();
expect(days[0].toFullString()).toBe('2022-07-31 00:00:00 星期日 狮子座');
});
test('test2', () => {
const month = SolarMonth.fromYm(2022, 7);
const weeks = month.getWeeks(0);
const lastWeek = weeks[weeks.length - 1];
const days = lastWeek.getDays();
expect(days[1].toFullString()).toBe('2022-08-01 00:00:00 星期一 (建军节) 狮子座');
});
test('test3', () => {
const month = SolarMonth.fromYm(2022, 7);
const weeks = month.getWeeks(0);
const lastWeek = weeks[weeks.length - 1];
const days = lastWeek.getDays();
expect(days[6].toFullString()).toBe('2022-08-06 00:00:00 星期六 狮子座');
});

View File

@@ -1,13 +1,13 @@
var {SolarMonth} = require('../lunar');
var {SolarSeason} = require('../lunar');
test('toString()', () => {
const month = SolarMonth.fromYm(2019, 5);
expect(month.toString()).toBe('2019-5');
expect(month.next(1).toString()).toBe('2019-6');
const season = SolarSeason.fromYm(2019, 5);
expect(season.toString()).toBe('2019.2');
expect(season.next(1).toString()).toBe('2019.3');
});
test('toFullString()', () => {
const month = SolarMonth.fromYm(2019, 5);
expect(month.toFullString()).toBe('2019年5月');
expect(month.next(1).toFullString()).toBe('2019年6月');
const season = SolarSeason.fromYm(2019, 5);
expect(season.toFullString()).toBe('2019年2季度');
expect(season.next(1).toFullString()).toBe('2019年3季度');
});

View File

@@ -31,3 +31,9 @@ test('test2', () => {
const week = SolarWeek.fromYmd(2021, 5, 4, start);
expect(week.getIndex()).toBe(2);
});
test('test3', () => {
const start = 0;
const week = SolarWeek.fromYmd(2022, 3, 6, start);
expect(week.getIndexInYear()).toBe(11);
});

View File

@@ -31,3 +31,30 @@ it('test3', () => {
expect(yun.getStartDay()).toBe(0);
expect(yun.getStartSolar().toYmd()).toBe('2020-02-06');
});
it('test4', () => {
const solar = Solar.fromYmdHms(2022, 3, 9, 20, 51, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
const yun = eightChar.getYun(1);
expect(yun.getStartSolar().toYmd()).toBe('2030-12-19');
});
it('test5', () => {
const solar = Solar.fromYmdHms(2022, 3, 9, 20, 51, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
const yun = eightChar.getYun(1, 2);
expect(yun.getStartYear()).toBe(8);
expect(yun.getStartMonth()).toBe(9);
expect(yun.getStartDay()).toBe(2);
expect(yun.getStartSolar().toYmd()).toBe('2030-12-12');
});
it('test6', () => {
const solar = Solar.fromYmdHms(2018, 6, 11, 9, 30, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
const yun = eightChar.getYun(0, 2);
expect(yun.getStartSolar().toYmd()).toBe('2020-03-21');
});

181
lunar.js

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
{
"name": "lunar-javascript",
"version": "1.2.27",
"version": "1.2.33",
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
"main": "index.js",
"scripts": {
@@ -50,6 +50,5 @@
"homepage": "https://github.com/6tail/lunar-javascript",
"devDependencies": {
"jest": "^26.6.3"
},
"dependencies": {}
}
}