diff --git a/CHANGELOG.md b/CHANGELOG.md index ca9b8a06c..0122c7cb1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.28(2024-04-15) +# 5.8.28(2024-04-16) ### 🐣新特性 * 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee) @@ -16,6 +16,7 @@ * 【core 】 修复FileMagicNumber.getMagicNumber空指针问题(issue#I9FE8B@Gitee) * 【extra 】 修复CompressUtil工具多出\问题(issue#I71K5V@Gitee) * 【db 】 解决oracle情况下setObject(inputStream)报错问题,java.sql.SQLException: 无效的列类型问题(pr#1207@Gitee) +* 【core 】 解决CalendarUtil.isSameDay时区不同导致结果错误问题(pr#3548@Github) ------------------------------------------------------------------------------------------------------------- # 5.8.27(2024-03-29) diff --git a/hutool-core/src/main/java/cn/hutool/core/date/CalendarUtil.java b/hutool-core/src/main/java/cn/hutool/core/date/CalendarUtil.java index 477b12d09..2c133e18f 100644 --- a/hutool-core/src/main/java/cn/hutool/core/date/CalendarUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/date/CalendarUtil.java @@ -5,6 +5,7 @@ import cn.hutool.core.convert.NumberChineseFormatter; import cn.hutool.core.date.format.DateParser; import cn.hutool.core.date.format.FastDateParser; import cn.hutool.core.date.format.GlobalCustomFormat; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -356,9 +357,10 @@ public class CalendarUtil { throw new IllegalArgumentException("The date must not be null"); } - // 统一时区 - cal1 = toDefaultTimeZone(cal1); - cal2 = toDefaultTimeZone(cal2); + if(ObjUtil.notEqual(cal1.getTimeZone(), cal2.getTimeZone())){ + // 统一时区 + cal2 = changeTimeZone(cal2, cal1.getTimeZone()); + } return cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) && // cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && // @@ -424,9 +426,10 @@ public class CalendarUtil { throw new IllegalArgumentException("The date must not be null"); } - // 统一时区 - cal1 = toDefaultTimeZone(cal1); - cal2 = toDefaultTimeZone(cal2); + if(ObjUtil.notEqual(cal1.getTimeZone(), cal2.getTimeZone())){ + // 统一时区 + cal2 = changeTimeZone(cal2, cal1.getTimeZone()); + } return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && // cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && @@ -805,10 +808,10 @@ public class CalendarUtil { * @param cal 时间 * @return 默认时区的calendar对象 */ - private static Calendar toDefaultTimeZone(Calendar cal) { + private static Calendar changeTimeZone(Calendar cal, TimeZone timeZone) { // 转换到统一时区,例如UTC cal = (Calendar) cal.clone(); - cal.setTimeZone(TimeZone.getDefault()); + cal.setTimeZone(timeZone); return cal; } }