LocalDateTimeUtil.parse改为blank检查

This commit is contained in:
Looly 2022-06-20 12:25:23 +08:00
parent 6c1281242b
commit e27b24005d
3 changed files with 9 additions and 3 deletions

View File

@ -13,6 +13,7 @@
* 【core 】 修改ObjectUtil.isNull逻辑issue#I5COJF@Gitee * 【core 】 修改ObjectUtil.isNull逻辑issue#I5COJF@Gitee
* 【core 】 BlockPolicy增加线程池关闭后的逻辑pr#660@Gitee * 【core 】 BlockPolicy增加线程池关闭后的逻辑pr#660@Gitee
* 【core 】 Ipv4Util增加ipv4ToLong重载pr#661@Gitee * 【core 】 Ipv4Util增加ipv4ToLong重载pr#661@Gitee
* 【core 】 LocalDateTimeUtil.parse改为blank检查issue#I5CZJ9@Gitee
* *
### 🐞Bug修复 ### 🐞Bug修复
* 【extra 】 修复createExtractor中抛出异常后流未关闭问题pr#2384@Github * 【extra 】 修复createExtractor中抛出异常后流未关闭问题pr#2384@Github

View File

@ -229,7 +229,7 @@ public class LocalDateTimeUtil {
* @return {@link LocalDateTime} * @return {@link LocalDateTime}
*/ */
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) { public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) {
if (null == text) { if (StrUtil.isBlank(text)) {
return null; return null;
} }
if (null == formatter) { if (null == formatter) {
@ -247,7 +247,7 @@ public class LocalDateTimeUtil {
* @return {@link LocalDateTime} * @return {@link LocalDateTime}
*/ */
public static LocalDateTime parse(CharSequence text, String format) { public static LocalDateTime parse(CharSequence text, String format) {
if (null == text) { if (StrUtil.isBlank(text)) {
return null; return null;
} }

View File

@ -11,7 +11,6 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.Date;
public class LocalDateTimeUtilTest { public class LocalDateTimeUtilTest {
@ -237,4 +236,10 @@ public class LocalDateTimeUtilTest {
final LocalDateTime of = LocalDateTimeUtil.of((TemporalAccessor) instant); final LocalDateTime of = LocalDateTimeUtil.of((TemporalAccessor) instant);
Console.log(of); Console.log(of);
} }
@Test
public void parseBlankTest(){
final LocalDateTime parse = LocalDateTimeUtil.parse("");
Assert.assertNull(parse);
}
} }