mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
6eb5a76f80
commit
8705f1b67c
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.18 (2021-12-21)
|
||||
# 5.7.18 (2021-12-22)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 新增CollStreamUtil.groupKeyValue(pr#479@Gitee)
|
||||
@ -14,6 +14,7 @@
|
||||
* 【core 】 excel添加写入图片的方法(pr#486@Gitee)
|
||||
* 【core 】 增加CollStreamUtil.groupBy(pr#484@Gitee)
|
||||
* 【core 】 增加CollUtil.setValueByMap(pr#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不再自动trim(issue#I4I04O@Gitee)
|
||||
* 【core 】 IdCardUtil.isValidCard不再自动trim(issue#I4I04O@Gitee)
|
||||
* 【core 】 改进TextFinder,支持限制结束位置及反向查找模式
|
||||
* 【core 】 Opt增加部分方法(pr#459@Gitee)
|
||||
* 【core 】 增加DefaultCloneable(pr#459@Gitee)
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user