Class DatePredicates
java.lang.Object
cloud.opencode.base.date.DatePredicates
Static Predicate Methods for Date/Time Objects
日期时间对象的静态谓词方法
This utility class provides a comprehensive set of predicate methods for testing
properties of date and time objects. All methods are null-safe and return false
when any argument is null.
此工具类提供一套完整的谓词方法,用于测试日期时间对象的属性。
所有方法均为空值安全,当任何参数为 null 时返回 false。
Features | 主要功能:
- Future/Past checks - 未来/过去检查
- Same day/month/year/week comparisons - 同日/同月/同年/同周比较
- Day-of-month position checks (first/last) - 月中日位置检查(首日/末日)
- Day-of-week checks (Monday through Sunday, weekend/weekday) - 星期几检查
- Leap year detection - 闰年检测
- Range inclusion (between) checks - 范围包含检查
Usage Examples | 使用示例:
LocalDate today = LocalDate.now();
LocalDate christmas = LocalDate.of(2026, 12, 25);
boolean future = DatePredicates.isFuture(christmas);
boolean weekend = DatePredicates.isWeekend(today);
boolean sameMonth = DatePredicates.isSameMonth(today, christmas);
boolean between = DatePredicates.isBetween(today,
LocalDate.of(2026, 1, 1), LocalDate.of(2026, 12, 31));
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-date V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if the given date is between start and end (inclusive on both ends).static booleanisBetween(LocalDateTime dateTime, LocalDateTime start, LocalDateTime end) Checks if the given date-time is between start and end (inclusive on both ends).static booleanisFirstDayOfMonth(LocalDate date) Checks if the given date is the first day of its month.static booleanChecks if the given date is a Friday.static booleanChecks if the given date is strictly after today.static booleanisFuture(LocalDateTime dateTime) Checks if the given date-time is strictly after the current date-time.static booleanisLastDayOfMonth(LocalDate date) Checks if the given date is the last day of its month.static booleanisLeapYear(LocalDate date) Checks if the given date falls in a leap year.static booleanChecks if the given date is a Monday.static booleanChecks if the given date is strictly before today.static booleanisPast(LocalDateTime dateTime) Checks if the given date-time is strictly before the current date-time.static booleanChecks if two dates represent the same day.static booleanChecks if two date-times represent the same day (ignoring time).static booleanisSameMonth(LocalDate a, LocalDate b) Checks if two dates fall in the same year and month.static booleanisSameWeek(LocalDate a, LocalDate b) Checks if two dates fall in the same ISO week (same week-based year and week number).static booleanisSameYear(LocalDate a, LocalDate b) Checks if two dates fall in the same year.static booleanisSaturday(LocalDate date) Checks if the given date is a Saturday.static booleanChecks if the given date is a Sunday.static booleanisThursday(LocalDate date) Checks if the given date is a Thursday.static booleanChecks if the given date is a Tuesday.static booleanisWednesday(LocalDate date) Checks if the given date is a Wednesday.static booleanChecks if the given date falls on a weekday (Monday through Friday).static booleanChecks if the given date falls on a weekend (Saturday or Sunday).
-
Method Details
-
isFuture
Checks if the given date is strictly after today. 检查给定日期是否严格在今天之后。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is in the future | 如果日期在未来则返回true
-
isFuture
Checks if the given date-time is strictly after the current date-time. 检查给定日期时间是否严格在当前日期时间之后。- Parameters:
dateTime- the date-time to check | 要检查的日期时间- Returns:
trueif the date-time is in the future | 如果日期时间在未来则返回true
-
isPast
Checks if the given date is strictly before today. 检查给定日期是否严格在今天之前。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is in the past | 如果日期在过去则返回true
-
isPast
Checks if the given date-time is strictly before the current date-time. 检查给定日期时间是否严格在当前日期时间之前。- Parameters:
dateTime- the date-time to check | 要检查的日期时间- Returns:
trueif the date-time is in the past | 如果日期时间在过去则返回true
-
isSameDay
-
isSameDay
Checks if two date-times represent the same day (ignoring time). 检查两个日期时间是否表示同一天(忽略时间部分)。- Parameters:
a- the first date-time | 第一个日期时间b- the second date-time | 第二个日期时间- Returns:
trueif both date-times fall on the same day | 如果两个日期时间在同一天则返回true
-
isSameMonth
-
isSameYear
-
isSameWeek
Checks if two dates fall in the same ISO week (same week-based year and week number). 检查两个日期是否在同一 ISO 周(相同的基于周的年份和周数)。- Parameters:
a- the first date | 第一个日期b- the second date | 第二个日期- Returns:
trueif both dates are in the same ISO week | 如果两个日期在同一 ISO 周则返回true
-
isFirstDayOfMonth
Checks if the given date is the first day of its month. 检查给定日期是否为所在月份的第一天。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is the first day of the month | 如果日期是月份第一天则返回true
-
isLastDayOfMonth
Checks if the given date is the last day of its month. 检查给定日期是否为所在月份的最后一天。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is the last day of the month | 如果日期是月份最后一天则返回true
-
isMonday
Checks if the given date is a Monday. 检查给定日期是否为周一。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Monday | 如果日期为周一则返回true
-
isTuesday
Checks if the given date is a Tuesday. 检查给定日期是否为周二。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Tuesday | 如果日期为周二则返回true
-
isWednesday
Checks if the given date is a Wednesday. 检查给定日期是否为周三。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Wednesday | 如果日期为周三则返回true
-
isThursday
Checks if the given date is a Thursday. 检查给定日期是否为周四。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Thursday | 如果日期为周四则返回true
-
isFriday
Checks if the given date is a Friday. 检查给定日期是否为周五。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Friday | 如果日期为周五则返回true
-
isSaturday
Checks if the given date is a Saturday. 检查给定日期是否为周六。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Saturday | 如果日期为周六则返回true
-
isSunday
Checks if the given date is a Sunday. 检查给定日期是否为周日。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Sunday | 如果日期为周日则返回true
-
isWeekend
Checks if the given date falls on a weekend (Saturday or Sunday). 检查给定日期是否为周末(周六或周日)。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is Saturday or Sunday | 如果日期为周六或周日则返回true
-
isWeekday
Checks if the given date falls on a weekday (Monday through Friday). 检查给定日期是否为工作日(周一至周五)。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the date is a weekday | 如果日期为工作日则返回true
-
isLeapYear
Checks if the given date falls in a leap year. 检查给定日期所在年份是否为闰年。- Parameters:
date- the date to check | 要检查的日期- Returns:
trueif the year is a leap year | 如果年份为闰年则返回true
-
isBetween
Checks if the given date is between start and end (inclusive on both ends). 检查给定日期是否在起始和结束之间(两端都包含)。Note: the range is not validated. If
startis afterend(an inverted range), this method silently returnsfalsefor every input — it does not throw.注意:不校验区间方向。若
start晚于end(倒置区间), 本方法对任何输入都静默返回false,不抛异常。- Parameters:
date- the date to check | 要检查的日期start- the start of the range (inclusive) | 范围起始(包含)end- the end of the range (inclusive) | 范围结束(包含)- Returns:
trueif the date is within the range | 如果日期在范围内则返回true
-
isBetween
Checks if the given date-time is between start and end (inclusive on both ends). 检查给定日期时间是否在起始和结束之间(两端都包含)。Note: the range is not validated. If
startis afterend(an inverted range), this method silently returnsfalsefor every input — it does not throw.注意:不校验区间方向。若
start晚于end(倒置区间), 本方法对任何输入都静默返回false,不抛异常。- Parameters:
dateTime- the date-time to check | 要检查的日期时间start- the start of the range (inclusive) | 范围起始(包含)end- the end of the range (inclusive) | 范围结束(包含)- Returns:
trueif the date-time is within the range | 如果日期时间在范围内则返回true
-