This commit is contained in:
Looly
2022-01-21 11:47:11 +08:00
parent f2462892d8
commit efeddc1469
3 changed files with 11 additions and 2 deletions

View File

@@ -92,7 +92,7 @@ public class ChineseDate {
offset -= daysOfMonth;
}
this.isLeapMonth = month == (leapMonth + 1);
this.isLeapMonth = leapMonth > 0 && (month == (leapMonth + 1));
if (hasLeapMonth && false == this.isLeapMonth) {
// 当前月份前有闰月,则月份显示要-1除非当前月份就是润月
month--;

View File

@@ -105,4 +105,12 @@ public class ChineseDateTest {
Assert.assertEquals("戊申猴年 五月初五", c1.toString());
Assert.assertEquals("戊申猴年 闰五月初五", c2.toString());
}
@Test
public void getChineseMonthTest2(){
//https://github.com/dromara/hutool/issues/2112
ChineseDate springFestival = new ChineseDate(DateUtil.parseDate("2022-02-01"));
final String chineseMonth = springFestival.getChineseMonth();
Assert.assertEquals("一月", chineseMonth);
}
}