### CSV File Format Example Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Example of the CSV file format used for configuring holidays and business hours. Supports comments, day-of-week hours, ordinal day hours, date-based holidays, and custom date formats. ```csv # Comment lines start with # # Configure business hours by day of week hours,sun,10-17 hours,mon,9-18 hours,tue,9-18 hours,wed,9-18 hours,thu,9-18 hours,fri,9-18 hours,sat,10-17 # Ordinal day hours (2nd Sunday, 24 hours) hours,2,sun,0-24 # Holidays by date holiday,2021/12/25,Christmas Day holiday,5/1,May Day # Change date format ymdFormat,M/d/yyyy holiday,1/1/2022,New Year ``` -------------------------------- ### Custom Holiday and Business Hour Logic with Predicates Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Define complex holiday rules and custom business hours using `Predicate` and lambda expressions. This example shows how to set a custom holiday for the last Monday of May and short business hours on Friday the 13th. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; import java.util.function.Function; // Custom predicate for last Monday of May (Memorial Day style) BusinessCalendar calendar = BusinessCalendar.newBuilder() .on(date -> date.getMonthValue() == 5 && date.getDayOfMonth() == date.with(TemporalAdjusters.lastInMonth(DayOfWeek.MONDAY)).getDayOfMonth()) .holiday("Last Monday of May") // Custom business hours predicate .on(date -> date.getDayOfWeek() == DayOfWeek.FRIDAY && date.getDayOfMonth() == 13) .hours("9-12") // Short day on Friday the 13th .hours("9-18") .build(); // Custom holiday function for complex logic Function customHoliday = date -> { // Company anniversary on first Monday of June if (date.getMonthValue() == 6 && date.getDayOfWeek() == DayOfWeek.MONDAY && date.getDayOfMonth() <= 7) { return "Company Anniversary"; } return null; }; BusinessCalendar customCalendar = BusinessCalendar.newBuilder() .holiday(customHoliday) .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); ``` -------------------------------- ### Get Holidays and Business Days in a Period in Java Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Query ranges of dates to return lists of holidays or business days. Ranges are inclusive of the start and end dates. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import one.cafebabe.businesscalendar4j.Holiday; import java.time.LocalDate; import java.util.List; BusinessCalendar calendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.PUBLIC_HOLIDAYS) .build(); LocalDate startOfYear = LocalDate.of(2021, 1, 1); LocalDate endOfYear = LocalDate.of(2021, 12, 31); // Get all holidays in 2021 List holidays = calendar.getHolidaysBetween(startOfYear, endOfYear); holidays.forEach(h -> System.out.println(h.date() + ": " + h.name())); // Output: // 2021-01-01: New Year's Day // 2021-01-18: Martin Luther King Jr. Day // 2021-05-31: Memorial Day // 2021-07-04: Independence Day // 2021-07-05: Independence Day (Observed) // 2021-09-06: Labor Day // 2021-11-11: Veterans Day // 2021-11-25: Thanksgiving Day // 2021-12-24: Christmas Day (Observed) // 2021-12-25: Christmas Day // Get all business days in January 2021 List businessDays = calendar.getBusinessDaysBetween( LocalDate.of(2021, 1, 1), LocalDate.of(2021, 1, 31)); System.out.println("Business days in Jan 2021: " + businessDays.size()); ``` -------------------------------- ### Find Next/Previous Business Hour Boundaries Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Calculate the start or end time of the next or previous business hour slot relative to a given date and time. Useful for scheduling. ```java BusinessCalendar cal = ... LocalDateTime may241023 = LocalDateTime.of(2021, 5, 24, 10, 23); System.out.println("When will this business hour slot close? " + cal.nextBusinessHourEnd(may241023)); System.out.println("When what the last business hour slot started? " + cal.lastBusinessHourStart(may241023)); ``` -------------------------------- ### Get Holidays and Business Days in a Period Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Retrieve lists of all holidays and business days within a specified date range. Uses `LocalDateTime` for the start and end of the period. ```java BusinessCalendar cal = ... List holidays = cal.getHolidaysBetween(LocalDateTime.of(2021, 1, 1), LocalDateTime.of(2021, 12, 21)); System.out.println("Holidays in 2021: " + holidays); List businessDays = cal.getBusinessDaysBetween(LocalDateTime.of(2021, 1, 1), LocalDateTime.of(2021, 12, 21)); System.out.println("Business days in 2021: " + businessDays); ``` -------------------------------- ### Get Business Hour Slots for a Date Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Retrieve a list of `BusinessHourSlot` objects for a specified date. Returns an empty list if the date is a holiday. Requires `java.time.LocalDateTime`. ```java BusinessCalendar cal = ... LocalDateTime may24 = LocalDateTime.of(2021, 5, 24); // returns an empty list if the specified date is a holiday List slots = cal.getBusinessHourSlots(may24); System.out.println("Number of business hour slots on May 24, 2021: " + slots.size()); System.out.println("On May 24, 2021, the buness starts from: " + slots.get(0).from; ``` -------------------------------- ### Initialize Business Calendar Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Basic initialization of the Business Calendar. Further configurations for holidays and business hours are chained after newBuilder(). ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() // where you configure holidays and business hours .build(); ``` -------------------------------- ### Create a Basic Business Calendar Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Configure a business calendar with specific date holidays, recurring annual holidays, day-of-week based holidays, and ordinal day holidays using the builder pattern. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import java.time.DayOfWeek; // Create a basic business calendar BusinessCalendar calendar = BusinessCalendar.newBuilder() // Configure specific date holidays .on(1995, 5, 23).holiday("Java public debut") // Configure recurring annual holidays (month, day) .on(5, 19).holiday("James Gosling's birthday") // Configure day-of-week based holidays .on(DayOfWeek.SUNDAY).holiday("Closed on Sundays") // Configure ordinal day holidays (2nd Monday of every month) .on(2, DayOfWeek.MONDAY).holiday("Closed on every 2nd Monday") .build(); ``` -------------------------------- ### Configure Holidays and Business Hours from File System CSV Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Load holiday and business hour configurations from a CSV file located on the file system. ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() .csv(Paths.get("holidays-business-hours.csv")) .build(); ``` -------------------------------- ### Configure Holidays and Business Hours from URL CSV Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Load holiday and business hour configurations from a CSV file accessible via a URL. ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() .csv(new URL("https://somewhere.example.com/holidays-business-hours.csv")) .build(); ``` -------------------------------- ### Configure CSV with Hourly Reload Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Load configurations from a CSV file and set it to automatically reload every hour. ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() .csv(Paths.get("holidays-business-hours.csv"), Duration.of(1, ChronoUnit.HOURS)) .build(); ``` -------------------------------- ### Equivalent Business Hour Expression Formats Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Demonstrates various equivalent string formats for specifying business hours, including 24-hour notation, 12-hour notation with AM/PM, and natural language terms. It also shows the use of different separators like commas and ampersands. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; // All these expressions are equivalent for "Opens from midnight to 8:30am, // 9am to noon, 1:30pm to 5pm, 7:31pm to midnight" String[] equivalentFormats = { "0-8:30,9-12,13:30-17,19:31-24", "0-8:30,9-12,13:30-17,19:31-0", "0-8:30,9-12pm,1:30pm-5pm,7:31pm-12am", "12 a.m.-8:30,9-12noon, 1:30pm-5pm, 7:31pm-12am", "12 a.m. - 8:30, 9 - noon,1:30pm-5pm,7:31pm-12am", "midnight - 8:30, 9- noon, 1:30pm-5pm,7:31pm-12 midnight", "12 a.m. to 8:30, 9-12,1:30pm to 5pm, 7:31pm-12am" }; // Using various separators: comma, ampersand, Japanese comma BusinessCalendar calendar = BusinessCalendar.newBuilder() .hours("9-12 & 13-17") // Ampersand separator .build(); ``` -------------------------------- ### Configure Business Hours by Month-Day and Day of Week Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Specify business hours for particular dates (like New Year's Eve) or recurring days of the week. ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() // opens 10am to 12pm, 1pm to 3pm on New Year's Eve .on(12, 31).hours("10 - 12, 13-15") // Saturday and Sunday: 10am to 11:30pm, 1pm to 4:30pm .on(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY) .hours("10AM-11:30 a.m., 1pm to 4:30pm") // from Monday to Friday: 9am to 6pm .hours("9-18") .build(); ``` -------------------------------- ### Configure CSV with On-Demand Reload Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Load configurations from a CSV file using a CsvConfiguration instance, allowing manual reloading. ```java CsvConfiguration conf = CsvConfiguration.getInstance(Paths.get("holidayconf.csv")); BusinessCalendar calendar = BusinessCalendar.newBuilder() .csv(conf); .build(); . . . // reload at anytime you need. conf.reload(); ``` -------------------------------- ### Gradle Dependency Declaration Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Add this dependency to your build.gradle file to include the Business Calendar library. ```gradle dependencies { compile 'one.cafebabe:businessCalendar4j:17.0.0' } ``` -------------------------------- ### Configure All US Holidays Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Apply all predefined US public holidays to a BusinessCalendar instance. This simplifies the configuration for standard US holidays. ```java BusinessCalendar usCal = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.PUBLIC_HOLIDAYS) .build(); ``` -------------------------------- ### Configure Business Hours with Flexible Time Strings Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Use the `hours()` method to set business hours with flexible time formats. Supports 24-hour, 12-hour AM/PM, and natural language. Special hours can be defined for specific dates or days of the week. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import one.cafebabe.businesscalendar4j.BusinessHourSlot; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; BusinessCalendar calendar = BusinessCalendar.newBuilder() // Special hours on New Year's Eve .on(12, 31).hours("10-12, 13-15") // Weekend hours .on(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY).hours("10AM-11:30am, 12 noon to 4:30pm") // Default weekday hours (evaluated last as fallback) .hours("9-18") .build(); // Check if specific time is during business hours LocalDateTime thursdayMorning = LocalDateTime.of(2021, 5, 20, 9, 30); System.out.println(calendar.isBusinessHour(thursdayMorning)); // true LocalDateTime saturdayMorning = LocalDateTime.of(2021, 5, 22, 9, 30); System.out.println(calendar.isBusinessHour(saturdayMorning)); // false (opens at 10) // Check if current time is during business hours boolean isOpenNow = calendar.isBusinessHour(); // Get business hour slots for a specific date List slots = calendar.getBusinessHourSlots(LocalDate.of(2021, 12, 31)); System.out.println(slots); // [BusinessHourSlot[from=2021-12-31T10:00, to=2021-12-31T12:00], ...] ``` -------------------------------- ### Dumping Calendar Information with Default and Custom Formats Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Use the `dump()` method to generate a human-readable summary of holidays and business hours for a specified date range. This is useful for debugging and verifying calendar configurations. The method supports both default and custom date formats. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import java.time.DayOfWeek; import java.time.LocalDate; BusinessCalendar calendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.PUBLIC_HOLIDAYS) .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .on(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY).hours("10-16") .hours("9-18") .build(); // Dump with default date format (yyyy/MM/dd) String dump = calendar.dump(LocalDate.of(2021, 7, 1), LocalDate.of(2021, 7, 7)); System.out.println(dump); // Dump with custom date format String customDump = calendar.dump(LocalDate.of(2021, 7, 1), LocalDate.of(2021, 7, 7), "MM/dd/yyyy"); ``` -------------------------------- ### Configure Holidays by Day of Week Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Define holidays based on specific days of the week or recurring patterns like every second Monday. ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() // fixed holiday by day of weeks. .on(DayOfWeek.SUNDAY, DayOfWeek.Wednesday) .holiday("closed on Sunday an Wednesday") // occurs every 2nd Monday .on(2, DayOfWeek.Monday).holiday("closed on every 2nd Monday") .build(); ``` -------------------------------- ### Load Holidays and Business Hours from CSV Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Configure business hours and holidays by loading data from CSV files using `csv()`. Supports loading from file paths or URLs, with options for automatic reloading or manual control. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import one.cafebabe.businesscalendar4j.CsvConfiguration; import java.nio.file.Paths; import java.net.URL; import java.time.Duration; import java.time.temporal.ChronoUnit; // Load from file path BusinessCalendar fromFile = BusinessCalendar.newBuilder() .csv(Paths.get("holidays-business-hours.csv")) .build(); // Load from URL BusinessCalendar fromUrl = BusinessCalendar.newBuilder() .csv(new URL("https://example.com/holidays.csv")) .build(); // Load with automatic reload every hour BusinessCalendar autoReload = BusinessCalendar.newBuilder() .csv(Paths.get("holidays.csv"), Duration.of(1, ChronoUnit.HOURS)) .build(); // Manual reload control CsvConfiguration conf = CsvConfiguration.getInstance(Paths.get("holidays.csv")); BusinessCalendar manualReload = BusinessCalendar.newBuilder() .csv(conf) .build(); // Later, trigger reload on demand conf.reload(); ``` -------------------------------- ### Navigate Business Hour Time Boundaries Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Use navigation methods like `nextBusinessHourEnd()` and `lastBusinessHourStart()` to find the boundaries of business hours relative to a given time. Requires a configured `BusinessCalendar` instance. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import java.time.LocalDateTime; BusinessCalendar calendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .hours("9-12, 13-17") // Morning and afternoon shifts .build(); LocalDateTime midMorning = LocalDateTime.of(2021, 5, 24, 10, 30); // When does the current business hour slot end? LocalDateTime nextEnd = calendar.nextBusinessHourEnd(midMorning); System.out.println(nextEnd); // 2021-05-24T12:00 // When did the current business hour slot start? LocalDateTime lastStart = calendar.lastBusinessHourStart(midMorning); System.out.println(lastStart); // 2021-05-24T09:00 // When does the next business hour slot start? LocalDateTime nextStart = calendar.nextBusinessHourStart(LocalDateTime.of(2021, 5, 24, 12, 30)); System.out.println(nextStart); // 2021-05-24T13:00 // When did the previous business hour slot end? LocalDateTime lastEnd = calendar.lastBusinessHourEnd(LocalDateTime.of(2021, 5, 24, 14, 0)); System.out.println(lastEnd); // 2021-05-24T12:00 ``` -------------------------------- ### Find First and Last Business Days in Java Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Locate the nearest business day on or after/before a specific date. The provided date is inclusive in the search. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import java.time.LocalDate; BusinessCalendar calendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.PUBLIC_HOLIDAYS) .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); // Find first business day on or after July 4, 2021 (Sunday + Independence Day observed Monday) LocalDate firstBizDay = calendar.firstBusinessDay(LocalDate.of(2021, 7, 4)); System.out.println(firstBizDay); // 2021-07-06 (Tuesday) // Find last business day on or before Jan 31, 2021 (Sunday) LocalDate lastBizDay = calendar.lastBusinessDay(LocalDate.of(2021, 1, 31)); System.out.println(lastBizDay); // 2021-01-29 (Friday) // Find first/last business day relative to today LocalDate firstFromToday = calendar.firstBusinessDay(); LocalDate lastFromToday = calendar.lastBusinessDay(); ``` -------------------------------- ### Configure Fixed Holidays Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Set specific holidays by year-month-day or as recurring annual holidays. ```java BusinessCalendar calendar = BusinessCalendar.newBuilder() // fixed one-time holiday .on(1995, 5, 23).holiday("Java public debut") // occurs every year .on(5, 19).holiday("James Gosling's birthday") .build(); ``` -------------------------------- ### Maven Dependency Declaration Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Add this dependency to your pom.xml to include the Business Calendar library. ```xml one.cafebabe businessCalendar4j 17.0.0 ``` -------------------------------- ### Find Next/Previous Holidays and Business Days Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Calculate the next or previous holiday or business day relative to a given date. The date provided is inclusive for holidays. ```java BusinessCalendar cal = ... System.out.println("What date is the next holiday? " + cal.firstHoliday(LocalDate.of(2021, 5, 24))); System.out.println("What date was the previous holiday? " + cal.lastHoliday(LocalDate.of(2021, 5, 24))); LocalDate independenceDay = LocalDate.of(2021, 7, 4); System.out.println("What date is the next business day? " + cal.firstBusinessDay(independenceDay)); System.out.println("What date was the previous business day? " + cal.lastBusinessDay(independenceDay)); ``` -------------------------------- ### Use Predefined Japanese Public Holidays Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Incorporate Japanese national holidays, with automatic calculation of substitute holidays and observance rules. Options include standard public holidays, New Year holiday periods, New Year's Eve, and weekend closures. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import java.time.LocalDate; // Use all Japanese public holidays BusinessCalendar japanCalendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.JAPAN.PUBLIC_HOLIDAYS) .build(); // Optional: Include New Year holiday period and New Year's Eve BusinessCalendar extendedJapanCalendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.JAPAN.PUBLIC_HOLIDAYS) .holiday(BusinessCalendar.JAPAN.CLOSED_ON_NEW_YEARS_HOLIDAYS) // Jan 1-3 .holiday(BusinessCalendar.JAPAN.CLOSED_ON_NEW_YEARS_EVE) // Dec 31 .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); // Get cabinet official holiday data range LocalDate firstDay = one.cafebabe.businesscalendar4j.Japan.getCabinetOfficialHolidayDataFirstDay(); LocalDate lastDay = one.cafebabe.businesscalendar4j.Japan.getCabinetOfficialHolidayDataLastDay(); ``` -------------------------------- ### Check Holidays and Business Days in Java Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Use isHoliday() and isBusinessDay() to validate dates against configured holiday rules. Calling these methods without arguments defaults to the current date. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import one.cafebabe.businesscalendar4j.Holiday; import java.time.LocalDate; BusinessCalendar calendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.PUBLIC_HOLIDAYS) .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); LocalDate july4 = LocalDate.of(2021, 7, 4); // Check specific date boolean isHoliday = calendar.isHoliday(july4); // true boolean isBusinessDay = calendar.isBusinessDay(july4); // false // Check today boolean isTodayHoliday = calendar.isHoliday(); boolean isTodayBusinessDay = calendar.isBusinessDay(); // Get holiday details Holiday holiday = calendar.getHoliday(july4); System.out.println(holiday.date() + ": " + holiday.name()); // 2021-07-04: Independence Day ``` -------------------------------- ### Java Modularity Declaration Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Declare the module requirement in your module-info.java file. ```java require one.cafebabe.businessCalendar4j ``` -------------------------------- ### Configure Weekend Closures Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Configure the calendar to be closed on Saturdays and Sundays. This is a common requirement for many business operations. ```java BusinessCalendar weekDays = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); ``` -------------------------------- ### Configure Japanese Holidays Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Apply predefined Japanese public holidays to a BusinessCalendar instance. This is useful for applications operating within Japan. ```java BusinessCalendar japanCal = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.JAPAN.PUBLIC_HOLIDAYS) .build(); ``` -------------------------------- ### Configure US Holidays Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Apply predefined US holidays like Martin Luther King Jr. Day and Independence Day to a BusinessCalendar instance. Ensure the BusinessCalendar class is imported. ```java BusinessCalendar usCal = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.MARTIN_LUTHER_KING_JR_DAY) .holiday(BusinessCalendar.UNITED_STATES.INDEPENDENCE_DAY) .build(); ``` -------------------------------- ### Use Predefined US Public Holidays Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Utilize predefined US federal holidays, including options for automatic Saturday/Sunday substitution handling. You can include all public holidays or select specific ones. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import static one.cafebabe.businesscalendar4j.BusinessCalendar.UNITED_STATES; import static one.cafebabe.businesscalendar4j.BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS; import java.time.LocalDate; // Use all US public holidays BusinessCalendar usCalendar = BusinessCalendar.newBuilder() .holiday(UNITED_STATES.PUBLIC_HOLIDAYS) .build(); // Or select specific holidays with weekend closures BusinessCalendar customCalendar = BusinessCalendar.newBuilder() .holiday(UNITED_STATES.NEW_YEARS_DAY, UNITED_STATES.MARTIN_LUTHER_KING_JR_DAY, UNITED_STATES.MEMORIAL_DAY, UNITED_STATES.INDEPENDENCE_DAY, UNITED_STATES.LABOR_DAY, UNITED_STATES.VETERANS_DAY, UNITED_STATES.THANKSGIVING_DAY, UNITED_STATES.CHRISTMAS_DAY, CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); // Check holidays System.out.println(usCalendar.isHoliday(LocalDate.of(2021, 1, 1))); // true (New Year's Day) System.out.println(usCalendar.getHoliday(LocalDate.of(2021, 1, 18))); // Holiday[date=2021-01-18, name=Martin Luther King Jr. Day] ``` -------------------------------- ### Find First and Last Holidays in Java Source: https://context7.com/yusuke/businesscalendar4j/llms.txt Retrieve the nearest holiday object relative to a given date. These methods return a Holiday object containing the date and name. ```java import one.cafebabe.businesscalendar4j.BusinessCalendar; import one.cafebabe.businesscalendar4j.Holiday; import java.time.LocalDate; BusinessCalendar calendar = BusinessCalendar.newBuilder() .holiday(BusinessCalendar.UNITED_STATES.PUBLIC_HOLIDAYS) .holiday(BusinessCalendar.CLOSED_ON_SATURDAYS_AND_SUNDAYS) .build(); // Find first holiday on or after Dec 20, 2021 Holiday nextHoliday = calendar.firstHoliday(LocalDate.of(2021, 12, 20)); System.out.println(nextHoliday); // Holiday[date=2021-12-24, name=Christmas Day (Observed)] // Find last holiday on or before Nov 12, 2021 Holiday prevHoliday = calendar.lastHoliday(LocalDate.of(2021, 11, 12)); System.out.println(prevHoliday); // Holiday[date=2021-11-11, name=Veterans Day] // Find first/last holiday relative to today Holiday firstFromToday = calendar.firstHoliday(); Holiday lastFromToday = calendar.lastHoliday(); ``` -------------------------------- ### Test Specific Date Holiday Status Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Determine if a specific date is a holiday or a business day. Requires a `BusinessCalendar` instance and a `java.time.LocalDate` object. ```java BusinessCalendar cal = ... LocalDate may24 = LocalDate.of(2021, 5, 24); System.out.println("Is it holiday? " + cal.isHoliday(may24)); System.out.println("Is it business day? " + cal.isBusinessDay(may24)); ``` -------------------------------- ### Test Current Day Holiday Status Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Check if the current day is a holiday or a business day using the `isHoliday()` and `isBusinessDay()` methods. Requires a configured BusinessCalendar instance. ```java BusinessCalendar cal = ... System.out.println("Is it holiday? " + cal.isHoliday()); System.out.println("Is it business day? " + cal.isBusinessDay()); ``` -------------------------------- ### Test Current Business Hour Status Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Check if the current time falls within business hours using the `isBusinessHour()` method. This requires a configured `BusinessCalendar` instance. ```java BusinessCalendar cal = ... System.out.println("Is it open? " + cal.isBusinessHour()); ``` -------------------------------- ### Test Specific Time Business Hour Status Source: https://github.com/yusuke/businesscalendar4j/blob/main/README.md Determine if a specific date and time falls within business hours. Requires a `BusinessCalendar` instance and a `java.time.LocalDateTime` object. ```java BusinessCalendar cal = ... LocalDateTime may241023 = LocalDateTime.of(2021, 5, 24, 10, 23); System.out.println("Is it open? " + cal.isBusinessHour(may241023)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.