add method

This commit is contained in:
Looly 2021-12-22 00:48:31 +08:00
parent 6eb5a76f80
commit 8705f1b67c
4 changed files with 31 additions and 9 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.18 (2021-12-21)
# 5.7.18 (2021-12-22)
### 🐣新特性
* 【core 】 新增CollStreamUtil.groupKeyValuepr#479@Gitee
@ -14,6 +14,7 @@
* 【core 】 excel添加写入图片的方法pr#486@Gitee
* 【core 】 增加CollStreamUtil.groupBypr#484@Gitee
* 【core 】 增加CollUtil.setValueByMappr#482@Gitee
* 【core 】 LocalDateTimeUtil增加endOfDay重载issue#2025@Github
*
### 🐞Bug修复
* 【core 】 LineReadWatcher#onModify文件清空判断问题issue#2013@Github
@ -35,7 +36,6 @@
* 【core 】 Tree增加filter、filterNew、cloneTree、hasChild方法issue#I4HFC6@Gitee
* 【poi 】 增加ColumnSheetReader及ExcelReader.readColumn支持读取某一列
* 【core 】 IdCardUtil.isValidCard不再自动trimissue#I4I04O@Gitee
* 【core 】 IdCardUtil.isValidCard不再自动trimissue#I4I04O@Gitee
* 【core 】 改进TextFinder支持限制结束位置及反向查找模式
* 【core 】 Opt增加部分方法pr#459@Gitee
* 【core 】 增加DefaultCloneablepr#459@Gitee

View File

@ -117,7 +117,7 @@ public enum DateField {
* {@link Calendar}相关值转换为DatePart枚举对象<br>
*
* @param calendarPartIntValue Calendar中关于Week的int值
* @return {@link DateField}
* @return DateField
*/
public static DateField of(int calendarPartIntValue) {
switch (calendarPartIntValue) {

View File

@ -27,10 +27,9 @@ import java.util.TimeZone;
/**
* JDK8+中的{@link LocalDateTime} 工具类封装
*
* @author looly
* @see DateUtil java7和一下版本使用Date工具类
* @see DatePattern 常用格式工具类
*
* @author looly
* @since 5.3.9
*/
public class LocalDateTimeUtil {
@ -259,7 +258,7 @@ public class LocalDateTimeUtil {
return null;
}
if(GlobalCustomFormat.isCustomFormat(format)){
if (GlobalCustomFormat.isCustomFormat(format)) {
return of(GlobalCustomFormat.parse(text, format));
}
@ -478,6 +477,25 @@ public class LocalDateTimeUtil {
* @return 一天的结束时间
*/
public static LocalDateTime endOfDay(LocalDateTime time) {
return endOfDay(time, false);
}
/**
* 修改为一天的结束时间例如
* <ul>
* <li>毫秒不归零2020-02-02 23:59:59,999</li>
* <li>毫秒归零2020-02-02 23:59:59,000</li>
* </ul>
*
* @param time 日期时间
* @param truncateMillisecond 是否毫秒归零
* @return 一天的结束时间
* @since 5.7.18
*/
public static LocalDateTime endOfDay(LocalDateTime time, boolean truncateMillisecond) {
if(truncateMillisecond){
return time.with(LocalTime.of(23, 59, 59));
}
return time.with(LocalTime.MAX);
}
@ -500,7 +518,7 @@ public class LocalDateTimeUtil {
* @return 是否为周末周六或周日
* @since 5.7.6
*/
public static boolean isWeekend(LocalDateTime localDateTime){
public static boolean isWeekend(LocalDateTime localDateTime) {
return isWeekend(localDateTime.toLocalDate());
}
@ -511,7 +529,7 @@ public class LocalDateTimeUtil {
* @return 是否为周末周六或周日
* @since 5.7.6
*/
public static boolean isWeekend(LocalDate localDate){
public static boolean isWeekend(LocalDate localDate) {
final DayOfWeek dayOfWeek = localDate.getDayOfWeek();
return DayOfWeek.SATURDAY == dayOfWeek || DayOfWeek.SUNDAY == dayOfWeek;
}

View File

@ -146,8 +146,12 @@ public class LocalDateTimeUtilTest {
@Test
public void endOfDayTest() {
final LocalDateTime localDateTime = LocalDateTimeUtil.parse("2020-01-23T12:23:56");
final LocalDateTime endOfDay = LocalDateTimeUtil.endOfDay(localDateTime);
LocalDateTime endOfDay = LocalDateTimeUtil.endOfDay(localDateTime);
Assert.assertEquals("2020-01-23T23:59:59.999999999", endOfDay.toString());
endOfDay = LocalDateTimeUtil.endOfDay(localDateTime, true);
Assert.assertEquals("2020-01-23T23:59:59", endOfDay.toString());
}
@Test