diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d7fc9d4..27d944913 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,11 @@ ------------------------------------------------------------------------------------------------------------- -# 5.8.6.M1 (2022-08-11) +# 5.8.6.M1 (2022-08-15) ### 🐣新特性 * 【core 】 CollUtil新增addIfAbsent方法(pr#750@Gitee) +* 【core 】 DateUtil.parseUTC支持只有时分的格式(issue#I5M6DP@Gitee) * ### 🐞Bug修复 * 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java b/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java index 66a04dd25..e2f415285 100755 --- a/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java @@ -834,7 +834,7 @@ public class DateUtil extends CalendarUtil { if (utcString == null) { return null; } - int length = utcString.length(); + final int length = utcString.length(); if (StrUtil.contains(utcString, 'Z')) { if (length == DatePattern.UTC_PATTERN.length() - 4) { // 格式类似:2018-09-13T05:34:31Z,-4表示减去4个单引号的长度 @@ -871,6 +871,9 @@ public class DateUtil extends CalendarUtil { if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 2) { // 格式类似:2018-09-13T05:34:31 return parse(utcString, DatePattern.UTC_SIMPLE_FORMAT); + } else if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 5) { + // 格式类似:2018-09-13T05:34 + return parse(utcString + ":00", DatePattern.UTC_SIMPLE_FORMAT); } else if (StrUtil.contains(utcString, CharUtil.DOT)) { // 可能为: 2021-03-17T06:31:33.99 return parse(utcString, DatePattern.UTC_SIMPLE_MS_FORMAT); diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java index 4dd3c556e..e83c147c5 100755 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java @@ -990,4 +990,11 @@ public class CollUtilTest { super(name, age); } } + + @Test + public void getFirstTest(){ + final List nullList = null; + final Object first = CollUtil.getFirst(nullList); + Assert.assertNull(first); + } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java index 4d45b2bfa..d7ab1922c 100755 --- a/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java @@ -695,6 +695,15 @@ public class DateUtilTest { Assert.assertEquals("2021-03-30 12:56:51", parse.toString()); } + @Test + public void parseUTCTest3() { + // issue#I5M6DP + final String dateStr = "2022-08-13T09:30"; + final DateTime dateTime = DateUtil.parse(dateStr); + Assert.assertNotNull(dateTime); + Assert.assertEquals("2022-08-13 09:30:00", dateTime.toString()); + } + @Test public void parseCSTTest() { final String dateStr = "Wed Sep 16 11:26:23 CST 2009";