mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fixed 178b994 from https://gitee.com/huahua522/hutool/pulls/511
fixed 4248036 from https://gitee.com/huahua522/hutool/pulls/509 增加对时间段重合的判断方法
This commit is contained in:
parent
9a88945386
commit
41651781b1
@ -5,24 +5,13 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.core.util.ReUtil;
|
import cn.hutool.core.util.ReUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
import java.time.*;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.Period;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.DateTimeFormatterBuilder;
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
import java.time.temporal.ChronoField;
|
import java.time.temporal.*;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.time.temporal.Temporal;
|
|
||||||
import java.time.temporal.TemporalAccessor;
|
|
||||||
import java.time.temporal.TemporalUnit;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDK8+中的{@link LocalDateTime} 工具类封装
|
* JDK8+中的{@link LocalDateTime} 工具类封装
|
||||||
@ -493,7 +482,7 @@ public class LocalDateTimeUtil {
|
|||||||
* @since 5.7.18
|
* @since 5.7.18
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime endOfDay(LocalDateTime time, boolean truncateMillisecond) {
|
public static LocalDateTime endOfDay(LocalDateTime time, boolean truncateMillisecond) {
|
||||||
if(truncateMillisecond){
|
if (truncateMillisecond) {
|
||||||
return time.with(LocalTime.of(23, 59, 59));
|
return time.with(LocalTime.of(23, 59, 59));
|
||||||
}
|
}
|
||||||
return time.with(LocalTime.MAX);
|
return time.with(LocalTime.MAX);
|
||||||
@ -544,4 +533,35 @@ public class LocalDateTimeUtil {
|
|||||||
public static Week dayOfWeek(LocalDate localDate) {
|
public static Week dayOfWeek(LocalDate localDate) {
|
||||||
return Week.of(localDate.getDayOfWeek());
|
return Week.of(localDate.getDayOfWeek());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第二个事件段是否在第一个时间段的内部
|
||||||
|
* 需要注意的是比如第一个时间段的结尾是23:59:59 第二天开始需要是00:00:00 相同也是重复
|
||||||
|
*
|
||||||
|
* @param realStartTime 第一个时间段的开始时间
|
||||||
|
* @param realEndTime 第一个时间段的结束时间
|
||||||
|
* @param startTime 第二个时间段的开始时间
|
||||||
|
* @param endTime 第二个时间段的结束时间
|
||||||
|
* @return true 表示时间有重合
|
||||||
|
*/
|
||||||
|
public static boolean isOverlap(LocalDateTime realStartTime, LocalDateTime realEndTime, LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return startTime.isAfter(realEndTime) || endTime.isBefore(realStartTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jdk新特新的支持,并没发现什么场合,因为拿不到泛型
|
||||||
|
* 第二个事件段是否在第一个时间段的内部
|
||||||
|
* 需要注意的是比如第一个时间段的结尾是23:59:59 第二天开始需要是00:00:00 相同也是重复
|
||||||
|
*
|
||||||
|
* @param realStartTime 第一个时间段的开始时间
|
||||||
|
* @param realEndTime 第一个时间段的结束时间
|
||||||
|
* @param startTime 第二个时间段的开始时间
|
||||||
|
* @param endTime 第二个时间段的结束时间
|
||||||
|
* @return true 表示没有时间有重合
|
||||||
|
*/
|
||||||
|
public static boolean isOverlap(Supplier<LocalDateTime> realStartTime, Supplier<LocalDateTime> realEndTime, Supplier<LocalDateTime> startTime, Supplier<LocalDateTime> endTime) {
|
||||||
|
return isOverlap(realStartTime.get(), realEndTime.get(), startTime.get(), endTime.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user