Class DaysAdjustment

  • All Implemented Interfaces:
    Resolvable<DateAdjuster>, Serializable, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class DaysAdjustment
    extends Object
    implements Resolvable<DateAdjuster>, org.joda.beans.ImmutableBean, Serializable
    An adjustment that alters a date by adding a period of days.

    When processing dates in finance, the rules for adjusting a date by a number of days can be complex. This class represents those rules, which operate in two steps - addition followed by adjustment. There are two main ways to perform the addition:

    Approach 1 - calendar days addition

    This approach is triggered by using the ofCalendarDays() factory methods. When adding a number of days to a date the addition is simple, no holidays or weekends apply. For example, two days after Friday 15th August would be Sunday 17th, even though this is typically a weekend. There are two steps in the calculation:

    In step one, the number of days is added without skipping any dates.

    In step two, the result of step one is optionally adjusted to be a business day using a BusinessDayAdjustment.

    Approach 2 - business days addition

    With this approach the days to be added are treated as business days. For example, two days after Friday 15th August would be Tuesday 19th, assuming a Saturday/Sunday weekend and no other applicable holidays.

    This approach is triggered by using the ofBusinessDays() factory methods. The distinction between business days, holidays and weekends is made using the specified holiday calendar. There are two steps in the calculation:

    In step one, the number of days is added using HolidayCalendar.shift(LocalDate, int).

    In step two, the result of step one is optionally adjusted to be a business day using a BusinessDayAdjustment.

    At first glance, step two may seem pointless, as the result of step one will always be a valid business day. However, the step two adjustment allows the possibility of applying a different holiday calendar.

    For example, a rule might have two parts: "first add 2 London business days, and then adjust the result to be a valid New York business day using the 'ModifiedFollowing' convention". Note that the holiday calendar differs in the two parts of the rule.

    See Also:
    Serialized Form
    • Field Detail

      • NONE

        public static final DaysAdjustment NONE
        An instance that performs no adjustment.
    • Method Detail

      • ofCalendarDays

        public static DaysAdjustment ofCalendarDays​(int numberOfDays)
        Obtains an instance that can adjust a date by a specific number of calendar days.

        When adjusting a date, the specified number of calendar days is added. Holidays and weekends are not taken into account in the calculation.

        No business day adjustment is applied to the result of the addition.

        Parameters:
        numberOfDays - the number of days
        Returns:
        the days adjustment
      • ofCalendarDays

        public static DaysAdjustment ofCalendarDays​(int numberOfDays,
                                                    BusinessDayAdjustment adjustment)
        Obtains an instance that can adjust a date by a specific number of calendar days.

        When adjusting a date, the specified number of calendar days is added. Holidays and weekends are not taken into account in the calculation.

        The business day adjustment is applied to the result of the addition.

        Parameters:
        numberOfDays - the number of days
        adjustment - the business day adjustment to apply to the result of the addition
        Returns:
        the days adjustment
      • ofBusinessDays

        public static DaysAdjustment ofBusinessDays​(int numberOfDays,
                                                    HolidayCalendarId holidayCalendar)
        Obtains an instance that can adjust a date by a specific number of business days.

        When adjusting a date, the specified number of business days is added. This is equivalent to repeatedly finding the next business day.

        No business day adjustment is applied to the result of the addition.

        If the input is a holiday, the first business day counted will be the next business day. If the input is a holiday and the number of days to add is zero, the result will be the next business day.

        Parameters:
        numberOfDays - the number of days
        holidayCalendar - the calendar that defines holidays and business days
        Returns:
        the days adjustment
      • ofBusinessDays

        public static DaysAdjustment ofBusinessDays​(int numberOfDays,
                                                    HolidayCalendarId holidayCalendar,
                                                    BusinessDayAdjustment adjustment)
        Obtains an instance that can adjust a date by a specific number of business days.

        When adjusting a date, the specified number of business days is added. This is equivalent to repeatedly finding the next business day.

        The business day adjustment is applied to the result of the addition.

        Parameters:
        numberOfDays - the number of days
        holidayCalendar - the calendar that defines holidays and business days
        adjustment - the business day adjustment to apply to the result of the addition
        Returns:
        the days adjustment
      • adjust

        public LocalDate adjust​(LocalDate date,
                                ReferenceData refData)
        Adjusts the date, adding the period in days using the holiday calendar and then applying the business day adjustment.

        The calculation is performed in two steps.

        Step one, use HolidayCalendar.shift(LocalDate, int) to add the number of days. If the holiday calendar is 'None' this will effectively add calendar days.

        Step two, use BusinessDayAdjustment.adjust(LocalDate, ReferenceData) to adjust the result of step one.

        Parameters:
        date - the date to adjust
        refData - the reference data, used to find the holiday calendar
        Returns:
        the adjusted date
      • resolve

        public DateAdjuster resolve​(ReferenceData refData)
        Resolves this adjustment using the specified reference data, returning an adjuster.

        This returns a DateAdjuster that performs the same calculation as this adjustment. It binds the holiday calendar, looked up from the reference data, into the result. As such, there is no need to pass the reference data in again.

        The resulting adjuster will be normalized.

        Specified by:
        resolve in interface Resolvable<DateAdjuster>
        Parameters:
        refData - the reference data, used to find the holiday calendar
        Returns:
        the adjuster, bound to a specific holiday calendar
      • getResultCalendar

        public HolidayCalendarId getResultCalendar()
        Gets the holiday calendar that will be applied to the result.

        This adjustment may contain more than one holiday calendar. This method returns the calendar used last. As such, the adjusted date will always be valid according to this calendar.

        Returns:
        the result holiday calendar
      • normalized

        public DaysAdjustment normalized()
        Normalizes the adjustment.

        If the number of days is zero, the calendar is set no 'NoHolidays'. If the number of days is non-zero and the calendar equals the adjustment calendar, the adjustment is removed.

        Returns:
        the normalized adjustment
      • toString

        public String toString()
        Returns a string describing the adjustment.
        Overrides:
        toString in class Object
        Returns:
        the descriptive string
      • meta

        public static DaysAdjustment.Meta meta()
        The meta-bean for DaysAdjustment.
        Returns:
        the meta-bean, not null
      • builder

        public static DaysAdjustment.Builder builder()
        Returns a builder used to create an instance of the bean.
        Returns:
        the builder, not null
      • metaBean

        public DaysAdjustment.Meta metaBean()
        Specified by:
        metaBean in interface org.joda.beans.Bean
      • getDays

        public int getDays()
        Gets the number of days to be added.

        When the adjustment is performed, this amount will be added to the input date using the calendar to determine the addition type.

        Returns:
        the value of the property, not null
      • getCalendar

        public HolidayCalendarId getCalendar()
        Gets the holiday calendar that defines the meaning of a day when performing the addition.

        When the adjustment is performed, this calendar is used to determine which days are business days.

        If the holiday calendar is 'None' then addition uses simple date addition arithmetic without considering any days as holidays or weekends. If the holiday calendar is anything other than 'None' then addition uses that calendar, effectively repeatedly finding the next business day.

        See the class-level documentation for more information.

        Returns:
        the value of the property, not null
      • getAdjustment

        public BusinessDayAdjustment getAdjustment()
        Gets the business day adjustment that is performed to the result of the addition.

        This adjustment is applied to the result of the period addition calculation. If the addition is performed using business days then any adjustment here is expected to have a different holiday calendar to that used during addition.

        If no adjustment is required, use the 'None' business day adjustment.

        See the class-level documentation for more information.

        Returns:
        the value of the property, not null
      • toBuilder

        public DaysAdjustment.Builder toBuilder()
        Returns a builder that allows this bean to be mutated.
        Returns:
        the mutable builder, not null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object