Skip to content

Commit

Permalink
v1.6.9 修复命宫、身宫的错误。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Jan 30, 2024
1 parent ce267b4 commit 9f3e2d2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 33 deletions.
45 changes: 44 additions & 1 deletion __tests__/EightChar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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('乙巳');
});
64 changes: 33 additions & 31 deletions lunar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex-zhiIndex);
if(jiaZiIndex>=60){
jiaZiIndex -= 60;
}
if(jiaZiIndex<0){
jiaZiIndex += 60;
var offset = monthZhiIndex + timeZhiIndex;
offset = (offset >= 14 ? 26 : 14) - offset;
var ganIndex = (this._p.lunar.getYearGanIndexExact() + 1) * 2 + offset;
while (ganIndex > 10) {
ganIndex -= 10;
}
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 jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
if(jiaZiIndex>=60){
jiaZiIndex -= 60;
var offset = monthZhiIndex + timeZhiIndex;
while (offset > 12) {
offset -= 12;
}
if(jiaZiIndex<0){
jiaZiIndex += 60;
var ganIndex = (this._p.lunar.getYearGanIndexExact() + 1) * 2 + (offset % 12);
while (ganIndex > 10) {
ganIndex -= 10;
}
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;},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 9f3e2d2

Please sign in to comment.