mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2026-05-29 18:57:11 +08:00
fix(TemporalUtil): 修复 offset(Temporal,DayOfWeek,boolean) 缺少 static 修饰符及 null 检查
工具类中该方法遗漏了 static 关键字,导致无法以工具类方式调用(需要先实例化 TemporalUtil)。 同时与同类的 offset(T, long, TemporalUnit) 方法保持一致,增加 null 检查, 避免传入 null 时抛出 NullPointerException。
This commit is contained in:
@@ -127,7 +127,7 @@ public class TemporalUtil {
|
||||
/**
|
||||
* 偏移到指定的周几
|
||||
*
|
||||
* @param temporal 日期或者日期时间
|
||||
* @param temporal 日期或者日期时间,为{@code null}返回{@code null}
|
||||
* @param dayOfWeek 周几
|
||||
* @param <T> 日期类型,如LocalDate或LocalDateTime
|
||||
* @param isPrevious 是否向前偏移,{@code true}向前偏移,{@code false}向后偏移。
|
||||
@@ -135,7 +135,10 @@ public class TemporalUtil {
|
||||
* @since 5.8.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Temporal> T offset(T temporal, DayOfWeek dayOfWeek, boolean isPrevious) {
|
||||
public static <T extends Temporal> T offset(T temporal, DayOfWeek dayOfWeek, boolean isPrevious) {
|
||||
if (null == temporal) {
|
||||
return null;
|
||||
}
|
||||
return (T) temporal.with(isPrevious ? TemporalAdjusters.previous(dayOfWeek) : TemporalAdjusters.next(dayOfWeek));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user