1
0
mirror of synced 2026-02-26 14:58:11 +08:00

v1.6.9 修复命宫、身宫的错误。

This commit is contained in:
6tail
2024-01-30 22:16:44 +08:00
parent ce267b4942
commit 9f3e2d29bd
3 changed files with 78 additions and 33 deletions

View File

@@ -152,7 +152,7 @@ test('身宫1', () => {
const solar = Solar.fromYmdHms(1994, 12, 6, 2, 0, 0);
const lunar = solar.getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getShenGong()).toBe('丑');
expect(eightChar.getShenGong()).toBe('丑');
});
test('身宫2', () => {
@@ -198,3 +198,46 @@ test('test19', () => {
})
expect(timeList).toStrictEqual(['1997-03-12 18:00:00', '1937-03-27 18:00:00']);
});
test('test20', () => {
const lunar = Solar.fromYmdHms(2024, 1, 29, 9, 30, 0).getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getMingGong()).toBe('癸亥');
expect(eightChar.getShenGong()).toBe('己未');
});
test('test21', () => {
expect(Solar.fromYmdHms(1990, 1, 27, 0, 0, 0).getLunar().getEightChar().getShenGong()).toBe('丙寅');
});
test('test23', () => {
expect(Solar.fromYmdHms(2019, 3, 7, 8, 0, 0).getLunar().getEightChar().getMingGong()).toBe('甲戌');
});
test('test24', () => {
expect(Solar.fromYmdHms(2019, 3, 27, 2, 0, 0).getLunar().getEightChar().getMingGong()).toBe('丁丑');
});
test('test25', () => {
expect(Lunar.fromYmdHms(1994, 5, 20, 18, 0 ,0).getEightChar().getMingGong()).toBe('丙寅');
});
test('test26', () => {
const lunar = Solar.fromYmdHms(1986, 2, 16, 8, 0, 0).getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getMingGong()).toBe('己亥');
expect(eightChar.getShenGong()).toBe('乙未');
});
test('test27', () => {
const lunar = Solar.fromYmdHms(1972, 11, 27, 10, 0, 0).getLunar();
const eightChar = lunar.getEightChar();
expect(eightChar.getShenGong()).toBe('乙巳');
});

View File

@@ -5712,53 +5712,55 @@
getMingGong:function(){
var monthZhiIndex = 0;
var timeZhiIndex = 0;
for(var i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
var zhi = LunarUtil.MONTH_ZHI[i];
if(lunar.getMonthZhiExact()===zhi){
var monthZhi = this.getMonthZhi();
var timeZhi = this.getTimeZhi();
var i,j;
for(i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
if(monthZhi===LunarUtil.MONTH_ZHI[i]){
monthZhiIndex = i;
break;
}
if(lunar.getTimeZhi()===zhi){
}
for(i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
if(timeZhi===LunarUtil.MONTH_ZHI[i]){
timeZhiIndex = i;
break;
}
}
var zhiIndex = 26 - (monthZhiIndex+timeZhiIndex);
if(zhiIndex>12){
zhiIndex -= 12;
var offset = monthZhiIndex + timeZhiIndex;
offset = (offset >= 14 ? 26 : 14) - offset;
var ganIndex = (this._p.lunar.getYearGanIndexExact() + 1) * 2 + offset;
while (ganIndex > 10) {
ganIndex -= 10;
}
var jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex-zhiIndex);
if(jiaZiIndex>=60){
jiaZiIndex -= 60;
}
if(jiaZiIndex<0){
jiaZiIndex += 60;
}
return LunarUtil.JIA_ZI[jiaZiIndex];
return LunarUtil.GAN[ganIndex] + LunarUtil.MONTH_ZHI[offset];
},
getMingGongNaYin:function(){return LunarUtil.NAYIN[this.getMingGong()];},
getShenGong:function(){
var monthZhiIndex = 0;
var timeZhiIndex = 0;
for(var i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
var zhi = LunarUtil.MONTH_ZHI[i];
if(lunar.getMonthZhiExact()===zhi){
var monthZhi = this.getMonthZhi();
var timeZhi = this.getTimeZhi();
var i,j;
for(i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
if(monthZhi===LunarUtil.MONTH_ZHI[i]){
monthZhiIndex = i;
break;
}
if(lunar.getTimeZhi()===zhi){
}
for(i=0,j=LunarUtil.ZHI.length;i<j;i++){
if(timeZhi===LunarUtil.ZHI[i]){
timeZhiIndex = i;
break;
}
}
var zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
if (zhiIndex > 12) {
zhiIndex -= 12;
var offset = monthZhiIndex + timeZhiIndex;
while (offset > 12) {
offset -= 12;
}
var jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
if(jiaZiIndex>=60){
jiaZiIndex -= 60;
var ganIndex = (this._p.lunar.getYearGanIndexExact() + 1) * 2 + (offset % 12);
while (ganIndex > 10) {
ganIndex -= 10;
}
if(jiaZiIndex<0){
jiaZiIndex += 60;
}
return LunarUtil.JIA_ZI[jiaZiIndex];
return LunarUtil.GAN[ganIndex] + LunarUtil.MONTH_ZHI[offset];
},
getShenGongNaYin:function(){return LunarUtil.NAYIN[this.getShenGong()];},
getLunar:function(){return this._p.lunar;},

View File

@@ -1,6 +1,6 @@
{
"name": "lunar-javascript",
"version": "1.6.8",
"version": "1.6.9",
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
"main": "index.js",
"scripts": {