From 9f3e2d29bd7726137cb2256c6f5fcd3d8dd4f7c0 Mon Sep 17 00:00:00 2001 From: 6tail <6tail@6tail.cn> Date: Tue, 30 Jan 2024 22:16:44 +0800 Subject: [PATCH] =?UTF-8?q?v1.6.9=20=E4=BF=AE=E5=A4=8D=E5=91=BD=E5=AE=AB?= =?UTF-8?q?=E3=80=81=E8=BA=AB=E5=AE=AB=E7=9A=84=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/EightChar.test.js | 45 +++++++++++++++++++++++++- lunar.js | 64 +++++++++++++++++++------------------ package.json | 2 +- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/__tests__/EightChar.test.js b/__tests__/EightChar.test.js index 0a5bdcf..c8dad0a 100644 --- a/__tests__/EightChar.test.js +++ b/__tests__/EightChar.test.js @@ -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('乙巳'); +}); diff --git a/lunar.js b/lunar.js index e56d673..623d39f 100644 --- a/lunar.js +++ b/lunar.js @@ -5712,53 +5712,55 @@ getMingGong:function(){ var monthZhiIndex = 0; var timeZhiIndex = 0; - for(var i=0,j=LunarUtil.MONTH_ZHI.length;i12){ - 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 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;}, diff --git a/package.json b/package.json index 210779e..8f51834 100644 --- a/package.json +++ b/package.json @@ -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": {