Interface HolidayProvider


public interface HolidayProvider
Interface for providing holiday data 节假日数据提供者接口

This interface defines the contract for providing holiday information. Implementations can provide data from various sources like configuration files, databases, or external APIs.

此接口定义了提供节假日信息的契约。实现可以从配置文件、数据库或外部API等各种来源提供数据。

Features | 主要功能:

  • Holiday data retrieval by year - 按年份检索假日数据
  • Holiday checking for specific dates - 检查特定日期是否为假日
  • Special workday support - 特殊工作日支持
  • Country/region identification - 国家/地区标识

Usage Examples | 使用示例:

HolidayProvider provider = new ChinaHolidayProvider();
List<Holiday> holidays = provider.getHolidays(2024);
boolean isHoliday = provider.isHoliday(LocalDate.of(2024, 10, 1));

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: Implementation dependent - 空值安全: 取决于实现
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the set of dates that are adjusted workdays (补班日) 获取调休工作日的日期集合(补班日)
    Gets the country/region code 获取国家/地区代码
    Gets the holiday for a specific date 获取指定日期的节假日
    getHolidays(int year)
    Gets all holidays for a specific year 获取指定年份的所有节假日
    Gets holidays in a date range 获取日期范围内的节假日
    Gets the provider name 获取提供者名称
    int[]
    Gets the supported year range 获取支持的年份范围
    boolean
    Checks if a date is an adjusted workday (补班日) 检查日期是否为调休工作日(补班日)
    boolean
    Checks if a date is a holiday 检查日期是否为节假日
    boolean
    Checks if a date is a workday 检查日期是否为工作日
    default boolean
    isYearSupported(int year)
    Checks if a year is supported 检查年份是否受支持
    default void
    Refreshes the holiday data (if applicable) 刷新节假日数据(如果适用)
  • Method Details

    • getName

      String getName()
      Gets the provider name 获取提供者名称
      Returns:
      the provider name | 提供者名称
    • getCountryCode

      String getCountryCode()
      Gets the country/region code 获取国家/地区代码
      Returns:
      the country code (e.g., "CN", "US") | 国家代码(如"CN"、"US")
    • getHolidays

      List<Holiday> getHolidays(int year)
      Gets all holidays for a specific year 获取指定年份的所有节假日
      Parameters:
      year - the year | 年份
      Returns:
      list of holidays | 节假日列表
    • getHolidays

      List<Holiday> getHolidays(LocalDate start, LocalDate end)
      Gets holidays in a date range 获取日期范围内的节假日
      Parameters:
      start - the start date (inclusive) | 起始日期(包含)
      end - the end date (inclusive) | 结束日期(包含)
      Returns:
      list of holidays | 节假日列表
    • isHoliday

      boolean isHoliday(LocalDate date)
      Checks if a date is a holiday 检查日期是否为节假日
      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if it's a holiday | 如果是节假日返回true
    • getHoliday

      Optional<Holiday> getHoliday(LocalDate date)
      Gets the holiday for a specific date 获取指定日期的节假日
      Parameters:
      date - the date | 日期
      Returns:
      the holiday, or empty if not a holiday | 节假日,如果不是节假日则为空
    • isWorkday

      boolean isWorkday(LocalDate date)
      Checks if a date is a workday 检查日期是否为工作日

      This considers both weekends and holidays.

      这同时考虑周末和节假日。

      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if it's a workday | 如果是工作日返回true
    • getAdjustedWorkdays

      Set<LocalDate> getAdjustedWorkdays(int year)
      Gets the set of dates that are adjusted workdays (补班日) 获取调休工作日的日期集合(补班日)
      Parameters:
      year - the year | 年份
      Returns:
      set of adjusted workday dates | 调休工作日日期集合
    • isAdjustedWorkday

      boolean isAdjustedWorkday(LocalDate date)
      Checks if a date is an adjusted workday (补班日) 检查日期是否为调休工作日(补班日)
      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if it's an adjusted workday | 如果是调休工作日返回true
    • getSupportedYearRange

      int[] getSupportedYearRange()
      Gets the supported year range 获取支持的年份范围
      Returns:
      array of [minYear, maxYear] | [最小年份, 最大年份]数组
    • isYearSupported

      default boolean isYearSupported(int year)
      Checks if a year is supported 检查年份是否受支持
      Parameters:
      year - the year | 年份
      Returns:
      true if supported | 如果支持返回true
    • refresh

      default void refresh()
      Refreshes the holiday data (if applicable) 刷新节假日数据(如果适用)