From 7188eab94cff488a96aa384421d29bfa749106c8 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 10 Jul 2025 11:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`ChineseDate=20`=E9=97=B0?= =?UTF-8?q?=E5=B9=B4=E9=97=B0=E6=9C=88=E8=8A=82=E6=97=A5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../java/cn/hutool/core/date/ChineseDate.java | 2 +- .../core/date/chinese/IssueICL1BTTest.java | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueICL1BTTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index dca02b2df..db36640d9 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### 🐞Bug修复 * 【extra 】 `Sftp``reconnectIfTimeout`方法改为捕获所有异常(issue#3989@Github) +* 【core 】 修复`ChineseDate `闰年闰月节日获取问题(issue#ICL1BT@Gitee) ------------------------------------------------------------------------------------------------------------- # 5.8.39(2025-06-20) diff --git a/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java b/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java index 3bdda284d..6fe15d444 100644 --- a/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java +++ b/hutool-core/src/main/java/cn/hutool/core/date/ChineseDate.java @@ -329,7 +329,7 @@ public class ChineseDate { * @return 获得农历节日 */ public String getFestivals() { - return StrUtil.join(",", LunarFestival.getFestivals(this.year, this.month, day)); + return StrUtil.join(",", LunarFestival.getFestivals(this.year, this.isLeapMonth ? this.month - 1 : this.month, day)); } /** diff --git a/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueICL1BTTest.java b/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueICL1BTTest.java new file mode 100644 index 000000000..b1e539d27 --- /dev/null +++ b/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueICL1BTTest.java @@ -0,0 +1,21 @@ +package cn.hutool.core.date.chinese; + +import cn.hutool.core.date.ChineseDate; +import cn.hutool.core.date.DateUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Date; + +public class IssueICL1BTTest { + @Test + void getFestivalsTest(){ + String date = "2025-07-31"; + Date productionDate = DateUtil.parseDate( date); + ChineseDate chineseDate = new ChineseDate(productionDate); + System.out.println(chineseDate.isLeapMonth()); + Assertions.assertTrue(chineseDate.isLeapMonth()); + String festivals = chineseDate.getFestivals(); + Assertions.assertEquals("", festivals); + } +}