diff --git a/__tests__/Solar.test.js b/__tests__/Solar.test.js index 8e4bac7..37b79c9 100644 --- a/__tests__/Solar.test.js +++ b/__tests__/Solar.test.js @@ -134,3 +134,18 @@ test('25', () => { }) expect(timeList).toStrictEqual(['1959-12-17 16:00:00']); }); + +test('26', () => { + const solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextMonth(2).toYmd()).toBe('2023-10-31'); +}); + +test('27', () => { + const solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextYear(2).toYmd()).toBe('2025-08-31'); +}); + +test('28', () => { + const solar = Solar.fromYmd(2023, 8, 31); + expect(solar.nextMonth(6).toYmd()).toBe('2024-02-29'); +}); diff --git a/lunar.js b/lunar.js index f40af20..1d65376 100644 --- a/lunar.js +++ b/lunar.js @@ -350,19 +350,17 @@ var y = this._p.year + years; var m = this._p.month; var d = this._p.day; - // 2月处理 - if (2 === m) { + if (1582 === y && 10 === m) { + if (d > 4 && d < 15) { + d += 10; + } + } else if (2 === m) { if (d > 28) { if (!SolarUtil.isLeapYear(y)) { d = 28; } } } - if (1582 === y && 10 === m) { - if (d > 4 && d < 15) { - d += 10; - } - } return _fromYmdHms(y, m, d, this._p.hour, this._p.minute, this._p.second); }, nextMonth:function(months){ @@ -375,18 +373,15 @@ var y = month.getYear(); var m = month.getMonth(); var d = this._p.day; - // 2月处理 - if (2 === m) { - if (d > 28) { - if (!SolarUtil.isLeapYear(y)) { - d = 28; - } - } - } if (1582 === y && 10 === m) { if (d > 4 && d < 15) { d += 10; } + } else { + var maxDay = SolarUtil.getDaysOfMonth(y, m); + if (d > maxDay) { + d = maxDay; + } } return _fromYmdHms(y, m, d, this._p.hour, this._p.minute, this._p.second); }, @@ -4536,7 +4531,7 @@ '9-9':'{jr.chongYang}', '12-8':'{jr.laBa}' }, - OTHER_FESTIVAL:{'1-4':['接神日'],'1-5':['隔开日'],'1-7':['人日'],'1-8':['谷日','顺星节'],'1-9':['天日'],'1-10':['地日'],'1-20':['天穿节'],'1-25':['填仓节'],'1-30':['正月晦'],'2-1':['中和节'],'2-2':['社日节'],'3-3':['上巳节'],'5-20':['分龙节'],'5-25':['会龙节'],'6-6':['天贶节'],'6-24':['观莲节'],'6-25':['五谷母节'],'7-14':['中元节'],'7-22':['财神节'],'7-29':['地藏节'],'8-1':['天灸日'],'10-1':['寒衣节'],'10-10':['十成节'],'10-15':['下元节'],'12-7':['驱傩日'],'12-16':['尾牙'],'12-24':['祭灶日']}, + OTHER_FESTIVAL:{'1-4':['接神日'],'1-5':['隔开日'],'1-7':['人日'],'1-8':['谷日','顺星节'],'1-9':['天日'],'1-10':['地日'],'1-20':['天穿节'],'1-25':['填仓节'],'1-30':['正月晦'],'2-1':['中和节'],'2-2':['社日节'],'3-3':['上巳节'],'5-20':['分龙节'],'5-25':['会龙节'],'6-6':['天贶节'],'6-24':['观莲节'],'6-25':['五谷母节'],'7-15':['中元节'],'7-22':['财神节'],'7-29':['地藏节'],'8-1':['天灸日'],'10-1':['寒衣节'],'10-10':['十成节'],'10-15':['下元节'],'12-7':['驱傩日'],'12-16':['尾牙'],'12-24':['祭灶日']}, CHONG:['{dz.wu}', '{dz.wei}', '{dz.shen}', '{dz.you}', '{dz.xu}', '{dz.hai}', '{dz.zi}', '{dz.chou}', '{dz.yin}', '{dz.mao}', '{dz.chen}', '{dz.si}'], CHONG_GAN:['{tg.wu}', '{tg.ji}', '{tg.geng}', '{tg.xin}', '{tg.ren}', '{tg.gui}', '{tg.jia}', '{tg.yi}', '{tg.bing}', '{tg.ding}'], CHONG_GAN_TIE:['{tg.ji}', '{tg.wu}', '{tg.xin}', '{tg.geng}', '{tg.gui}', '{tg.ren}', '{tg.yi}', '{tg.jia}', '{tg.ding}', '{tg.bing}'], diff --git a/package.json b/package.json index 5193634..d1a89e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lunar-javascript", - "version": "1.6.3", + "version": "1.6.4", "description": "lunar is a calendar library for Solar and Chinese Lunar.", "main": "index.js", "scripts": {