diff --git a/README.md b/README.md index 3a899f1..af0b866 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,4 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历) ## 文档 -请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html") +请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html") diff --git a/README_EN.md b/README_EN.md index b1e3316..3637b12 100644 --- a/README_EN.md +++ b/README_EN.md @@ -59,4 +59,4 @@ Output: ## Documentation -Please visit [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html") +Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html") diff --git a/__tests__/Lunar.test.js b/__tests__/Lunar.test.js index 714cfcc..92c8956 100644 --- a/__tests__/Lunar.test.js +++ b/__tests__/Lunar.test.js @@ -413,16 +413,6 @@ test('test022', () => { expect(lunar.getSolar().toString()).toBe('2033-12-22'); }); -test('test023', () => { - const lunar = Lunar.fromYmd(2022, 1, 1); - expect(lunar.getYearNineStar().toString()).toBe('六白金开阳'); -}); - -test('test024', () => { - const lunar = Lunar.fromYmd(2033, 1, 1); - expect(lunar.getYearNineStar().toString()).toBe('四绿木天权'); -}); - test('test025', () => { const solar = Solar.fromYmdHms(2021, 6, 7, 21, 18, 0); expect(solar.getLunar().toString()).toBe('二〇二一年四月廿七'); diff --git a/__tests__/NineStar.test.js b/__tests__/NineStar.test.js new file mode 100644 index 0000000..a18b9a2 --- /dev/null +++ b/__tests__/NineStar.test.js @@ -0,0 +1,16 @@ +const {Solar, Lunar} = require('../lunar'); + +test('test1', () => { + const lunar = Solar.fromYmd(1985, 2, 19).getLunar(); + expect(lunar.getYearNineStar().getNumber()).toBe('六'); +}); + +test('test023', () => { + const lunar = Lunar.fromYmd(2022, 1, 1); + expect(lunar.getYearNineStar().toString()).toBe('六白金开阳'); +}); + +test('test024', () => { + const lunar = Lunar.fromYmd(2033, 1, 1); + expect(lunar.getYearNineStar().toString()).toBe('四绿木天权'); +}); diff --git a/lunar.js b/lunar.js index 5d5185c..33aa9ce 100644 --- a/lunar.js +++ b/lunar.js @@ -1224,13 +1224,16 @@ return LunarUtil.YUE_XIANG[this._p.day]; }, _getYearNineStar:function(yearInGanZhi){ - var index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1; - var yearOffset = 0; - if (index !== LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) { - yearOffset = -1; + var indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1; + var index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1; + var yearOffset = indexExact - index; + if (yearOffset > 1) { + yearOffset -= 60; + } else if (yearOffset < -1) { + yearOffset += 60; } var yuan = Math.floor((this._p.year + yearOffset + 2696) / 60) % 3; - var offset = (62 + yuan * 3 - index) % 9; + var offset = (62 + yuan * 3 - indexExact) % 9; if(0 === offset){ offset = 9; } @@ -1952,23 +1955,15 @@ }, getWeeks:function(start){ var l = []; - var cy = this._p.year; - var cm = this._p.month; - var weeks = SolarUtil.getWeeksOfMonth(cy, cm, start); - var days = SolarUtil.getDaysOfMonth(cy, cm); - for(var i = 0;i days) { - d -= days; - m++; - if (m > 12) { - y++; - m=m-12; - } + var week = SolarWeek.fromYmd(this._p.year, this._p.month, 1, start); + var firstDay = week.getFirstDay(); + while (true) { + l.push(week); + week = week.next(1, false); + firstDay = week.getFirstDay(); + if (firstDay.getYear() > this._p.year || firstDay.getMonth() > this._p.month) { + break; } - l.push(SolarWeek.fromYmd(y, m, d, start)); } return l; }, diff --git a/package.json b/package.json index a91012e..f0f1d40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lunar-javascript", - "version": "1.2.35", + "version": "1.2.36", "description": "lunar is a calendar library for Solar and Chinese Lunar.", "main": "index.js", "scripts": {