fix(TemporalUtil): 修复 offset(Temporal,DayOfWeek,boolean) 缺少 static 修饰符及 null 检查

工具类中该方法遗漏了 static 关键字,导致无法以工具类方式调用(需要先实例化 TemporalUtil)。
同时与同类的 offset(T, long, TemporalUnit) 方法保持一致,增加 null 检查,
避免传入 null 时抛出 NullPointerException。
This commit is contained in:
Busyliu
2026-03-02 05:35:54 +00:00
committed by Gitee
parent 6d99a39857
commit b0375a8c04

View File

@@ -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));
}
}