From c43ddb3ad56b897d837c2114be67d6940ea5fdf6 Mon Sep 17 00:00:00 2001 From: 6tail <6tail@6tail.cn> Date: Thu, 15 Oct 2020 19:39:23 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.22=20=E4=BF=AE=E5=A4=8D=E7=AB=8B=E6=98=A5?= =?UTF-8?q?=E8=87=B3=E6=AD=A3=E6=9C=88=E5=88=9D=E4=B8=80=E4=B9=8B=E9=97=B4?= =?UTF-8?q?=E5=85=AB=E5=AD=97=E5=B9=B4=E6=9C=88=E6=9F=B1=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B=E6=96=B0=E5=A2=9E=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=86=9C=E5=8E=86=E6=97=A5=E6=9C=9F=E7=9A=84=E6=8E=A8?= =?UTF-8?q?=E7=A7=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lunar.js | 105 ++++++++++++++++++++++++++++++++++++++++----------- package.json | 2 +- 2 files changed, 85 insertions(+), 22 deletions(-) diff --git a/lunar.js b/lunar.js index 30435b9..c4bcc3d 100644 --- a/lunar.js +++ b/lunar.js @@ -511,6 +511,7 @@ o['jieQi'][key] = Solar.fromJulianDay(_qiAccurate2(q) + Solar.J2000); }; var _computeYear = function(o,solar,year){ + //以正月初一开始 var yearGanIndex = (year+LunarUtil.BASE_YEAR_GANZHI_INDEX)%10; var yearZhiIndex = (year+LunarUtil.BASE_YEAR_GANZHI_INDEX)%12; @@ -522,37 +523,60 @@ var gExact = yearGanIndex; var zExact = yearZhiIndex; + //获取立春的阳历时刻 + var liChun = o['jieQi']['立春']; + + //阳历和阴历年份相同代表正月初一及以后 if(year===solar.getYear()){ - //获取立春的阳历时刻 - var liChun = o['jieQi']['立春']; //立春日期判断 if(solar.toYmd()=liChun.toYmd()) { + g++; + z++; + } + if(solar.toYmdHms()>=liChun.toYmdHms()) { + gExact++; + zExact++; } } + if(g<0){ + g += 10; + } + if(g>=10){ + g-=10; + } + if(z<0){ + z += 12; + } + if(z>=12){ + z-=12; + } + if(gExact<0){ + gExact += 10; + } + if(gExact>=10){ + gExact-=10; + } + if(zExact<0){ + zExact += 12; + } + if(zExact>=12){ + zExact-=12; + } + o['yearGanIndex'] = yearGanIndex; o['yearZhiIndex'] = yearZhiIndex; o['yearGanIndexByLiChun'] = g; o['yearZhiIndexByLiChun'] = z; - o['yearGanIndexExact'] = gExact; o['yearZhiIndexExact'] = zExact; }; @@ -1407,6 +1431,49 @@ } return this._p.eightChar; }, + next:function(days){ + var y = this._p.year,m = this._p.month,d = this._p.day,daysInMonth,rest; + if(days>0){ + daysInMonth = LunarUtil.getDaysOfMonth(y,m); + rest = day+days; + while(daysInMonth < rest) { + if(m>0){ + if(LunarUtil.getLeapMonth(y)!=m){ + m++; + }else{ + m = -m; + } + }else{ + m = 1-m; + } + if(13==m){ + y++; + m=1; + } + rest -= daysInMonth; + daysInMonth = LunarUtil.getDaysOfMonth(y,m); + } + d = rest; + }else if(days<0){ + daysInMonth = day; + rest = -days; + while(daysInMonth <= rest) { + if(m>0){ + m--; + if(0==m){ + y--; + m = LunarUtil.getLeapMonth(y)!=12?12:-12; + } + }else{ + m = -m; + } + rest -= daysInMonth; + daysInMonth = LunarUtil.getDaysOfMonth(y,m); + } + d = daysInMonth - rest; + } + return _fromYmdHms(y,m,d,this._p.hour,this._p.minute,this._p.second); + }, toString:function(){ return this.getYearInChinese()+'年'+this.getMonthInChinese()+'月'+this.getDayInChinese(); }, @@ -1975,15 +2042,11 @@ nextMonth:function(y,m){ var n = Math.abs(m)+1; if(m>0){ - var index = y-this.BASE_YEAR+this.BASE_INDEX; - var v = this.LUNAR_MONTH[2*index+1]; - v = (v>>4)&0x0F; - if(v===m){ + if(m==LunarUtil.getLeapMonth(y)){ n = -m; } } - if(n===13) n = 1; - return n; + return 13!=n?n:1; }, getDaysOfMonth:function(year,month){ var index = year-this.BASE_YEAR+this.BASE_INDEX; diff --git a/package.json b/package.json index 112a4dc..13a7118 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lunar-javascript", - "version": "1.0.21", + "version": "1.0.22", "description": "lunar is a calendar library for Solar and Chinese Lunar.", "main": "index.js", "scripts": {