修复ChineseDate 闰年闰月节日获取问题

This commit is contained in:
Looly
2025-07-10 11:54:13 +08:00
parent e6e32a76b9
commit 8ad16be6cb

View File

@@ -345,7 +345,7 @@ public class ChineseDate {
* @return 获得农历节日 * @return 获得农历节日
*/ */
public String getFestivals() { 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));
} }
/** /**
@@ -411,7 +411,7 @@ public class ChineseDate {
* @since 6.0.0 * @since 6.0.0
*/ */
public String toString(ChineseDateFormat format) { public String toString(ChineseDateFormat format) {
if(null == format){ if (null == format) {
format = ChineseDateFormat.MIX; format = ChineseDateFormat.MIX;
} }
@@ -420,12 +420,12 @@ public class ChineseDate {
String normalizedYear = GanZhi.getGanzhiOfYear(year); String normalizedYear = GanZhi.getGanzhiOfYear(year);
String normalizedMonth = getChineseMonth(); String normalizedMonth = getChineseMonth();
String normalizedDay = getChineseDay(); String normalizedDay = getChineseDay();
switch (format){ switch (format) {
case GXSS: case GXSS:
dateTemplate = "农历{}" + getChineseZodiac() + "年{}{}"; dateTemplate = "农历{}" + getChineseZodiac() + "年{}{}";
normalizedMonth = getChineseMonthName(); normalizedMonth = getChineseMonthName();
break; break;
case XSS : case XSS:
normalizedYear = getChineseZodiac(); normalizedYear = getChineseZodiac();
break; break;
case GSG: case GSG:
@@ -439,7 +439,7 @@ public class ChineseDate {
break; break;
case MIX: case MIX:
//根据选择的格式返回不同标准化日期输出默认为Mix //根据选择的格式返回不同标准化日期输出默认为Mix
dateTemplate = "公元"+ this.year +"年农历{}年{}{}"; dateTemplate = "公元" + this.year + "年农历{}年{}{}";
case GSS: case GSS:
break; break;
default: default: