mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复ChineseDate传入农历日期非闰月时获取公历错误问题
This commit is contained in:
@@ -80,7 +80,7 @@ public class ChineseDate {
|
||||
|
||||
year = iYear;
|
||||
// 计算农历月份
|
||||
int leapMonth = LunarInfo.leapMonth(iYear); // 闰哪个月,1-12
|
||||
final int leapMonth = LunarInfo.leapMonth(iYear); // 闰哪个月,1-12
|
||||
// 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
|
||||
int month;
|
||||
int daysOfMonth;
|
||||
@@ -136,6 +136,11 @@ public class ChineseDate {
|
||||
* @since 5.7.18
|
||||
*/
|
||||
public ChineseDate(int chineseYear, int chineseMonth, int chineseDay, boolean isLeapMonth) {
|
||||
if(chineseMonth != LunarInfo.leapMonth(chineseYear)){
|
||||
// issue#I5YB1A,用户传入的月份可能非闰月,此时此参数无效。
|
||||
isLeapMonth = false;
|
||||
}
|
||||
|
||||
this.day = chineseDay;
|
||||
// 当月是闰月的后边的月定义为闰月,如润的是五月,则5表示五月,6表示润五月
|
||||
this.isLeapMonth = isLeapMonth;
|
||||
|
@@ -1,13 +1,14 @@
|
||||
package cn.hutool.core.date.chinese;
|
||||
|
||||
import cn.hutool.core.date.ChineseDate;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IssueI5YB1ATest {
|
||||
@Test
|
||||
public void chineseDateTest() {
|
||||
public void chineseDateTest() {
|
||||
// 四月非闰月,因此isLeapMonth参数无效
|
||||
final ChineseDate date = new ChineseDate(2023, 4, 8, true);
|
||||
Console.log(date.getGregorianDate());
|
||||
Assert.assertEquals("2023-05-26 00:00:00", date.getGregorianDate().toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user