mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复ChineseDate传入农历日期非闰月时获取公历错误问题
This commit is contained in:
parent
3b98f64924
commit
ece502c526
@ -23,6 +23,7 @@
|
|||||||
* 【core 】 修复DefaultTrustManager空指针问题(issue#2716@Github)
|
* 【core 】 修复DefaultTrustManager空指针问题(issue#2716@Github)
|
||||||
* 【core 】 修复时间轮添加任务线程安全问题(pr#2712@Github)
|
* 【core 】 修复时间轮添加任务线程安全问题(pr#2712@Github)
|
||||||
* 【core 】 修复 BeanUtil#copyProperties 源对象与目标对象都是 Map 时设置忽略属性无效问题(pr#2698@Github)
|
* 【core 】 修复 BeanUtil#copyProperties 源对象与目标对象都是 Map 时设置忽略属性无效问题(pr#2698@Github)
|
||||||
|
* 【core 】 修复ChineseDate传入农历日期非闰月时获取公历错误问题(issue#I5YB1A@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.9 (2022-10-22)
|
# 5.8.9 (2022-10-22)
|
||||||
|
@ -80,7 +80,7 @@ public class ChineseDate {
|
|||||||
|
|
||||||
year = iYear;
|
year = iYear;
|
||||||
// 计算农历月份
|
// 计算农历月份
|
||||||
int leapMonth = LunarInfo.leapMonth(iYear); // 闰哪个月,1-12
|
final int leapMonth = LunarInfo.leapMonth(iYear); // 闰哪个月,1-12
|
||||||
// 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
|
// 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
|
||||||
int month;
|
int month;
|
||||||
int daysOfMonth;
|
int daysOfMonth;
|
||||||
@ -136,6 +136,11 @@ public class ChineseDate {
|
|||||||
* @since 5.7.18
|
* @since 5.7.18
|
||||||
*/
|
*/
|
||||||
public ChineseDate(int chineseYear, int chineseMonth, int chineseDay, boolean isLeapMonth) {
|
public ChineseDate(int chineseYear, int chineseMonth, int chineseDay, boolean isLeapMonth) {
|
||||||
|
if(chineseMonth != LunarInfo.leapMonth(chineseYear)){
|
||||||
|
// issue#I5YB1A,用户传入的月份可能非闰月,此时此参数无效。
|
||||||
|
isLeapMonth = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.day = chineseDay;
|
this.day = chineseDay;
|
||||||
// 当月是闰月的后边的月定义为闰月,如润的是五月,则5表示五月,6表示润五月
|
// 当月是闰月的后边的月定义为闰月,如润的是五月,则5表示五月,6表示润五月
|
||||||
this.isLeapMonth = isLeapMonth;
|
this.isLeapMonth = isLeapMonth;
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package cn.hutool.core.date.chinese;
|
package cn.hutool.core.date.chinese;
|
||||||
|
|
||||||
import cn.hutool.core.date.ChineseDate;
|
import cn.hutool.core.date.ChineseDate;
|
||||||
import cn.hutool.core.lang.Console;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class IssueI5YB1ATest {
|
public class IssueI5YB1ATest {
|
||||||
@Test
|
@Test
|
||||||
public void chineseDateTest() {
|
public void chineseDateTest() {
|
||||||
|
// 四月非闰月,因此isLeapMonth参数无效
|
||||||
final ChineseDate date = new ChineseDate(2023, 4, 8, true);
|
final ChineseDate date = new ChineseDate(2023, 4, 8, true);
|
||||||
Console.log(date.getGregorianDate());
|
Assert.assertEquals("2023-05-26 00:00:00", date.getGregorianDate().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user