Class DateAdjusters

java.lang.Object
cloud.opencode.base.date.adjuster.DateAdjusters

public final class DateAdjusters extends Object
Extended temporal adjusters for common date operations 扩展的时间调整器,用于常见日期操作

This class provides additional temporal adjusters beyond those in java.time.temporal.TemporalAdjusters, focused on business and common use cases.

此类提供比java.time.temporal.TemporalAdjusters更多的时间调整器, 专注于业务和常见用例。

Features | 主要功能:

  • Start/end of year, quarter, month, week - 年、季、月、周的开始/结束
  • Next/previous occurrence adjusters - 下一个/上一个发生调整器
  • Nth occurrence adjusters - 第N次发生调整器
  • Business day adjusters - 工作日调整器

Usage Examples | 使用示例:

LocalDate date = LocalDate.of(2024, 6, 15);

// Start of quarter
LocalDate startOfQ = date.with(DateAdjusters.startOfQuarter());
// 2024-04-01

// End of quarter
LocalDate endOfQ = date.with(DateAdjusters.endOfQuarter());
// 2024-06-30

// Next Monday
LocalDate nextMon = date.with(DateAdjusters.nextOrSame(DayOfWeek.MONDAY));

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: No (callers must provide non-null arguments) - 空值安全: 否(调用者必须提供非空参数)
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • startOfYear

      public static TemporalAdjuster startOfYear()
      Returns the start of the year adjuster 返回年初调整器
      Returns:
      the adjuster | 调整器
    • endOfYear

      public static TemporalAdjuster endOfYear()
      Returns the end of the year adjuster 返回年末调整器
      Returns:
      the adjuster | 调整器
    • startOfQuarter

      public static TemporalAdjuster startOfQuarter()
      Returns the start of the current quarter adjuster 返回当前季度开始调整器
      Returns:
      the adjuster | 调整器
    • endOfQuarter

      public static TemporalAdjuster endOfQuarter()
      Returns the end of the current quarter adjuster 返回当前季度结束调整器
      Returns:
      the adjuster | 调整器
    • startOfQuarter

      public static TemporalAdjuster startOfQuarter(int quarter)
      Returns the start of a specific quarter adjuster 返回特定季度开始调整器
      Parameters:
      quarter - the quarter (1-4) | 季度(1-4)
      Returns:
      the adjuster | 调整器
    • startOfMonth

      public static TemporalAdjuster startOfMonth()
      Returns the start of the month adjuster (alias for firstDayOfMonth) 返回月初调整器(firstDayOfMonth的别名)
      Returns:
      the adjuster | 调整器
    • endOfMonth

      public static TemporalAdjuster endOfMonth()
      Returns the end of the month adjuster (alias for lastDayOfMonth) 返回月末调整器(lastDayOfMonth的别名)
      Returns:
      the adjuster | 调整器
    • startOfWeek

      public static TemporalAdjuster startOfWeek()
      Returns the start of the week adjuster (Monday) 返回周初调整器(周一)
      Returns:
      the adjuster | 调整器
    • startOfWeek

      public static TemporalAdjuster startOfWeek(DayOfWeek firstDayOfWeek)
      Returns the start of the week adjuster for a specific first day 返回特定首日的周初调整器
      Parameters:
      firstDayOfWeek - the first day of week | 一周的第一天
      Returns:
      the adjuster | 调整器
    • endOfWeek

      public static TemporalAdjuster endOfWeek()
      Returns the end of the week adjuster (Sunday) 返回周末调整器(周日)
      Returns:
      the adjuster | 调整器
    • endOfWeek

      public static TemporalAdjuster endOfWeek(DayOfWeek lastDayOfWeek)
      Returns the end of the week adjuster for a specific last day 返回特定末日的周末调整器
      Parameters:
      lastDayOfWeek - the last day of week | 一周的最后一天
      Returns:
      the adjuster | 调整器
    • dayOfMonth

      public static TemporalAdjuster dayOfMonth(int day)
      Returns the nth day of the month adjuster 返回月份第N天调整器
      Parameters:
      day - the day of month | 月份的日期
      Returns:
      the adjuster | 调整器
    • nthDayOfWeekInMonth

      public static TemporalAdjuster nthDayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek)
      Returns the nth weekday of the month adjuster 返回月份第N个工作日调整器
      Parameters:
      ordinal - the ordinal (1-5, or -1 for last) | 序数(1-5,或-1表示最后)
      dayOfWeek - the day of week | 周几
      Returns:
      the adjuster | 调整器
    • nextOrSame

      public static TemporalAdjuster nextOrSame(DayOfWeek dayOfWeek)
      Returns an adjuster for the next or same occurrence of a day of week 返回下一个或相同星期几的调整器
      Parameters:
      dayOfWeek - the day of week | 星期几
      Returns:
      the adjuster | 调整器
    • previousOrSame

      public static TemporalAdjuster previousOrSame(DayOfWeek dayOfWeek)
      Returns an adjuster for the previous or same occurrence of a day of week 返回上一个或相同星期几的调整器
      Parameters:
      dayOfWeek - the day of week | 星期几
      Returns:
      the adjuster | 调整器
    • next

      public static TemporalAdjuster next(DayOfWeek dayOfWeek)
      Returns an adjuster for the next occurrence of a day of week (strictly after) 返回下一个星期几的调整器(严格之后)
      Parameters:
      dayOfWeek - the day of week | 星期几
      Returns:
      the adjuster | 调整器
    • previous

      public static TemporalAdjuster previous(DayOfWeek dayOfWeek)
      Returns an adjuster for the previous occurrence of a day of week (strictly before) 返回上一个星期几的调整器(严格之前)
      Parameters:
      dayOfWeek - the day of week | 星期几
      Returns:
      the adjuster | 调整器
    • startOfFirstHalf

      public static TemporalAdjuster startOfFirstHalf()
      Returns the start of the first half of the year 返回上半年开始
      Returns:
      the adjuster | 调整器
    • endOfFirstHalf

      public static TemporalAdjuster endOfFirstHalf()
      Returns the end of the first half of the year 返回上半年结束
      Returns:
      the adjuster | 调整器
    • startOfSecondHalf

      public static TemporalAdjuster startOfSecondHalf()
      Returns the start of the second half of the year 返回下半年开始
      Returns:
      the adjuster | 调整器
    • endOfSecondHalf

      public static TemporalAdjuster endOfSecondHalf()
      Returns the end of the second half of the year 返回下半年结束
      Returns:
      the adjuster | 调整器
    • nextMonthDay

      public static TemporalAdjuster nextMonthDay(Month month, int day)
      Returns an adjuster to the next occurrence of a specific month and day 返回下一个特定月日的调整器
      Parameters:
      month - the month | 月份
      day - the day of month | 日期
      Returns:
      the adjuster | 调整器
    • plusBusinessDays

      public static TemporalAdjuster plusBusinessDays(int days)
      Returns an adjuster for adding/subtracting business days 返回添加/减去工作日的调整器
      Parameters:
      days - the number of business days (can be negative) | 工作日数(可为负)
      Returns:
      the adjuster | 调整器
    • nearestWeekday

      public static TemporalAdjuster nearestWeekday()
      Returns an adjuster to the nearest weekday 返回最近工作日的调整器
      Returns:
      the adjuster | 调整器
    • plus

      public static TemporalAdjuster plus(long amount, ChronoUnit unit)
      Returns an adjuster that adds the specified number of units 返回添加指定数量单位的调整器
      Parameters:
      amount - the amount to add | 要添加的数量
      unit - the unit | 单位
      Returns:
      the adjuster | 调整器
    • minus

      public static TemporalAdjuster minus(long amount, ChronoUnit unit)
      Returns an adjuster that subtracts the specified number of units 返回减去指定数量单位的调整器
      Parameters:
      amount - the amount to subtract | 要减去的数量
      unit - the unit | 单位
      Returns:
      the adjuster | 调整器