Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f3e2d29bd |
@@ -152,7 +152,7 @@ test('身宫1', () => {
|
|||||||
const solar = Solar.fromYmdHms(1994, 12, 6, 2, 0, 0);
|
const solar = Solar.fromYmdHms(1994, 12, 6, 2, 0, 0);
|
||||||
const lunar = solar.getLunar();
|
const lunar = solar.getLunar();
|
||||||
const eightChar = lunar.getEightChar();
|
const eightChar = lunar.getEightChar();
|
||||||
expect(eightChar.getShenGong()).toBe('丁丑');
|
expect(eightChar.getShenGong()).toBe('乙丑');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('身宫2', () => {
|
test('身宫2', () => {
|
||||||
@@ -198,3 +198,46 @@ test('test19', () => {
|
|||||||
})
|
})
|
||||||
expect(timeList).toStrictEqual(['1997-03-12 18:00:00', '1937-03-27 18:00:00']);
|
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
lunar.js
64
lunar.js
@@ -5712,53 +5712,55 @@
|
|||||||
getMingGong:function(){
|
getMingGong:function(){
|
||||||
var monthZhiIndex = 0;
|
var monthZhiIndex = 0;
|
||||||
var timeZhiIndex = 0;
|
var timeZhiIndex = 0;
|
||||||
for(var i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
|
var monthZhi = this.getMonthZhi();
|
||||||
var zhi = LunarUtil.MONTH_ZHI[i];
|
var timeZhi = this.getTimeZhi();
|
||||||
if(lunar.getMonthZhiExact()===zhi){
|
var i,j;
|
||||||
|
for(i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
|
||||||
|
if(monthZhi===LunarUtil.MONTH_ZHI[i]){
|
||||||
monthZhiIndex = 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;
|
timeZhiIndex = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var zhiIndex = 26 - (monthZhiIndex+timeZhiIndex);
|
var offset = monthZhiIndex + timeZhiIndex;
|
||||||
if(zhiIndex>12){
|
offset = (offset >= 14 ? 26 : 14) - offset;
|
||||||
zhiIndex -= 12;
|
var ganIndex = (this._p.lunar.getYearGanIndexExact() + 1) * 2 + offset;
|
||||||
|
while (ganIndex > 10) {
|
||||||
|
ganIndex -= 10;
|
||||||
}
|
}
|
||||||
var jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex-zhiIndex);
|
return LunarUtil.GAN[ganIndex] + LunarUtil.MONTH_ZHI[offset];
|
||||||
if(jiaZiIndex>=60){
|
|
||||||
jiaZiIndex -= 60;
|
|
||||||
}
|
|
||||||
if(jiaZiIndex<0){
|
|
||||||
jiaZiIndex += 60;
|
|
||||||
}
|
|
||||||
return LunarUtil.JIA_ZI[jiaZiIndex];
|
|
||||||
},
|
},
|
||||||
getMingGongNaYin:function(){return LunarUtil.NAYIN[this.getMingGong()];},
|
getMingGongNaYin:function(){return LunarUtil.NAYIN[this.getMingGong()];},
|
||||||
getShenGong:function(){
|
getShenGong:function(){
|
||||||
var monthZhiIndex = 0;
|
var monthZhi = this.getMonthZhi();
|
||||||
var timeZhiIndex = 0;
|
var timeZhi = this.getTimeZhi();
|
||||||
for(var i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
|
var i,j;
|
||||||
var zhi = LunarUtil.MONTH_ZHI[i];
|
for(i=0,j=LunarUtil.MONTH_ZHI.length;i<j;i++){
|
||||||
if(lunar.getMonthZhiExact()===zhi){
|
if(monthZhi===LunarUtil.MONTH_ZHI[i]){
|
||||||
monthZhiIndex = 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;
|
timeZhiIndex = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
|
var offset = monthZhiIndex + timeZhiIndex;
|
||||||
if (zhiIndex > 12) {
|
while (offset > 12) {
|
||||||
zhiIndex -= 12;
|
offset -= 12;
|
||||||
}
|
}
|
||||||
var jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
|
var ganIndex = (this._p.lunar.getYearGanIndexExact() + 1) * 2 + (offset % 12);
|
||||||
if(jiaZiIndex>=60){
|
while (ganIndex > 10) {
|
||||||
jiaZiIndex -= 60;
|
ganIndex -= 10;
|
||||||
}
|
}
|
||||||
if(jiaZiIndex<0){
|
return LunarUtil.GAN[ganIndex] + LunarUtil.MONTH_ZHI[offset];
|
||||||
jiaZiIndex += 60;
|
|
||||||
}
|
|
||||||
return LunarUtil.JIA_ZI[jiaZiIndex];
|
|
||||||
},
|
},
|
||||||
getShenGongNaYin:function(){return LunarUtil.NAYIN[this.getShenGong()];},
|
getShenGongNaYin:function(){return LunarUtil.NAYIN[this.getShenGong()];},
|
||||||
getLunar:function(){return this._p.lunar;},
|
getLunar:function(){return this._p.lunar;},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lunar-javascript",
|
"name": "lunar-javascript",
|
||||||
"version": "1.6.8",
|
"version": "1.6.9",
|
||||||
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user