Package fr.marcwrobel.jbanking.calendar
Interface Calendar
- All Known Implementing Classes:
CompositeCalendar,ConfigurableCalendar,FinancialCalendars
public interface Calendar
A calendar that handles date calculations, taking bank
Holidays into account. Days that are not bank holidays are
called business days.
Subclasses of this interface are expected to be immutable and thread-safe.
Predefined calendars are available in FinancialCalendars.
Usage :
// Build a new calendar
Calendar calendar = new ConfigurableCalendar(
SATURDAY, SUNDAY, NEW_YEAR_DAY,
new MonthDayHoliday(JULY, 14),
new RelativeHoliday(WesternEaster.INSTANCE, 1) // easter monday
);
// Check holidays
Assertion.assertTrue(calendar.isHoliday(LocalDate.of(2022, 1, 1))); // Saturday and New Year's Day
Assertion.assertTrue(calendar.isHoliday(LocalDate.of(2022, 1, 2))); // Sunday
Assertion.assertTrue(calendar.isHoliday(LocalDate.of(2022, 7, 14))); // Bastille day in France
// Not an holiday
Assertion.assertFalse(calendar.isHoliday(LocalDate.of(2022, 1, 11)));
Assertion.assertTrue(calendar.isBusinessDay(LocalDate.of(2022, 1, 11)));
// Get business days
Assertion.assertEquals(LocalDate.of(2022, 1, 3), calendar.next(LocalDate.of(2022, 1, 1)));
Assertion.assertEquals(
Arrays.asList(LocalDate.of(2022, 1, 3), LocalDate.of(2022, 1, 4)),
calendar.businessDaysWithin(LocalDate.of(2022, 1, 1), LocalDate.of(2022, 1, 4)));
- Since:
- 2.1.0
- See Also:
-
HolidaysFinancialCalendars
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum number of iteration for date calculations before giving up. -
Method Summary
Modifier and TypeMethodDescriptionbusinessDaysWithin(LocalDate from, LocalDate to) Compute the business days betweenfrom(inclusive) andto(inclusive).getHolidaysFor(LocalDate date) Get all theHolidays matching with the given day.holidaysWithin(LocalDate from, LocalDate to) Compute the holidays betweenfrom(inclusive) andto(inclusive).default booleanisBusinessDay(LocalDate date) Check whether the given date is a business day.booleanCheck whether the given date is a public holiday.default LocalDateCompute the next business day after the given date (excluded).default LocalDatenextOrSame(LocalDate date) Compute the next business day after the given date (included).default LocalDateCompute the previous business day before the given date (excluded).default LocalDatepreviousOrSame(LocalDate date) Compute the previous business day before the given date (included).default LocalDateShifts the given date by the specified number of business days.
-
Field Details
-
MAX_ITERATIONS
static final int MAX_ITERATIONSMaximum number of iteration for date calculations before giving up.- See Also:
-
-
Method Details
-
isHoliday
Check whether the given date is a public holiday.- Parameters:
date- a non-null date.- Returns:
trueif the given date is a holiday,falseotherwise.
-
getHolidaysFor
Get all theHolidays matching with the given day.- Parameters:
date- a non-null and unmodifiable set ofHolidays.- Returns:
trueif the given date is a holiday,falseotherwise.
-
isBusinessDay
Check whether the given date is a business day.- Parameters:
date- a non-null date.- Returns:
trueif the given date is a business day,falseotherwise.
-
shift
Shifts the given date by the specified number of business days. If the given amount is- zero, the input date is returned,
- positive, later business days are chosen
- negative, earlier business days are chosen
- Parameters:
date- the date to shiftnumberOfDays- the number of business days to adjust by- Returns:
- a non-null date
- Throws:
DateCalculationException- if no business day could be found in a reasonable time
-
previous
Compute the previous business day before the given date (excluded).- Parameters:
date- a non-null date- Returns:
- a non-null date
- Throws:
DateCalculationException- if no business day could be found in a reasonable time
-
previousOrSame
Compute the previous business day before the given date (included).- Parameters:
date- a non-null date- Returns:
- a non-null date
- Throws:
DateCalculationException- if no business day could be found in a reasonable time
-
next
Compute the next business day after the given date (excluded).- Parameters:
date- a non-null date- Returns:
- a non-null date
- Throws:
DateCalculationException- if no business day could be found in a reasonable time
-
nextOrSame
Compute the next business day after the given date (included).- Parameters:
date- a non-null date- Returns:
- a non-null date
- Throws:
DateCalculationException- if no business day could be found in a reasonable time
-
holidaysWithin
Compute the holidays betweenfrom(inclusive) andto(inclusive).- Parameters:
from- a non-null dateto- a non-null date- Returns:
- a non-null and unmodifiable ordered list of dates
- Throws:
IllegalArgumentException- iffromis afterto
-
businessDaysWithin
Compute the business days betweenfrom(inclusive) andto(inclusive).- Parameters:
from- a non-null dateto- a non-null date- Returns:
- a non-null and unmodifiable ordered list of dates
- Throws:
IllegalArgumentException- iffromis afterto
-