From 9bfb4ea312d1bd4af59d45fef971bfc1d5676ccb Mon Sep 17 00:00:00 2001 From: 6tail <6tail@6tail.cn> Date: Fri, 7 Jan 2022 20:31:14 +0800 Subject: [PATCH] =?UTF-8?q?v1.2.23=20=E4=BC=98=E5=8C=96=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lunar.js | 57 +++++++++++++++++----------------------------------- package.json | 2 +- 2 files changed, 19 insertions(+), 40 deletions(-) diff --git a/lunar.js b/lunar.js index 57ebefc..d4b8dd0 100644 --- a/lunar.js +++ b/lunar.js @@ -1209,18 +1209,8 @@ if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) { yearOffset = -1; } - var n = 65; var yuan = Math.floor((this._p.year + yearOffset + 2696) / 60) % 3; - switch(yuan){ - case 2: - n = 68; - break; - case 0: - n = 62; - break; - default: - } - var offset = (n - index) % 9; + var offset = (62 + yuan * 3 - index) % 9; if(0 === offset){ offset = 9; } @@ -2130,6 +2120,8 @@ jieQiJulianDays: [] }, getYear:function(){return this._p.year;}, + getGanIndex:function(){return this._p.ganIndex;}, + getZhiIndex:function(){return this._p.zhiIndex;}, getGan:function(){return LunarUtil.GAN[this._p.ganIndex+1];}, getZhi:function(){return LunarUtil.ZHI[this._p.zhiIndex+1];}, getGanZhi:function(){return this.getGan()+this.getZhi();}, @@ -2216,22 +2208,13 @@ return _YUN[Math.floor((this._p.year+2696)/20)%9]+'运'; }, getNineStar:function(){ - var index = LunarUtil.getJiaZiIndex(this.getGanZhi())+1; - var n = 65; - switch(this.getYuan()){ - case '中元': - n = 68; - break; - case '下元': - n = 62; - break; - default: + var index = LunarUtil.getJiaZiIndex(this.getGanZhi()) + 1; + var yuan = Math.floor((this._p.year + 2696) / 60) % 3; + var offset = (62 + yuan * 3 - index) % 9; + if(0 === offset){ + offset = 9; } - var offset = (n-index)%9; - if(0===offset){ - offset=9; - } - return NineStar.fromIndex(offset-1); + return NineStar.fromIndex(offset - 1); }, getPositionXi:function(){ return LunarUtil.POSITION_XI[this._p.ganIndex+1]; @@ -2415,23 +2398,19 @@ getPositionTaiSuiDesc:function(){ return LunarUtil.POSITION_DESC[this.getPositionTaiSui()]; }, - getMonthNineStar:function(){ - var n = 12; - var yearZhi = LunarYear.fromYear(this._p.year).getZhi(); - if ('子午卯酉'.indexOf(yearZhi)>-1) { - n = 18; - } else if ('辰戌丑未'.indexOf(yearZhi)>-1) { - n = 15; - } + getNineStar:function(){ + var index = LunarYear.fromYear(this._p.year).getZhiIndex() % 3; var m = this._p.month; - if(m<0){ + if (m < 0) { m = -m; } - var offset = (n-m)%9; - if(0===offset){ - offset=9; + var monthZhiIndex = (13 + m) % 12; + var n = 27 - (index * 3); + if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) { + n -= 3; } - return NineStar.fromIndex(offset-1); + var offset = (n - monthZhiIndex) % 9; + return NineStar.fromIndex(offset); }, toString:function(){return this.getYear()+'年'+(this.isLeap()?'闰':'')+LunarUtil.MONTH[Math.abs(this.getMonth())]+'月('+this.getDayCount()+')天';} }; diff --git a/package.json b/package.json index 1a2c93c..816372d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lunar-javascript", - "version": "1.2.22", + "version": "1.2.23", "description": "lunar is a calendar library for Solar and Chinese Lunar.", "main": "index.js", "scripts": {