增加TemporalAccessorUtil.isIn

This commit is contained in:
Looly
2022-07-17 00:11:21 +08:00
parent 8a9025ac55
commit f2cde9a860
2 changed files with 19 additions and 0 deletions

View File

@@ -162,4 +162,22 @@ public class TemporalAccessorUtil extends TemporalUtil{
return result;
}
/**
* 当前日期是否在日期指定范围内<br>
* 起始日期和结束日期可以互换
*
* @param date 被检查的日期
* @param beginDate 起始日期(包含)
* @param endDate 结束日期(包含)
* @return 是否在范围内
* @since 5.8.5
*/
public static boolean isIn(TemporalAccessor date, TemporalAccessor beginDate, TemporalAccessor endDate){
final long thisMills = toEpochMilli(date);
final long beginMills = toEpochMilli(beginDate);
final long endMills = toEpochMilli(endDate);
return thisMills >= Math.min(beginMills, endMills) && thisMills <= Math.max(beginMills, endMills);
}
}