90 Day Weekend Adjuster

This examples will show how to find 90 days business days from a date using a custom Java 8 adjuster. The TemporalAdjuster interface, in the java.time.temporal package, adjustInto method accepts a temporal value and returns an adjusted value. The NinetyDayWeekendAdjuster will evaluate the passed in date and return 90 days excluding weekends by creating a date 90 days in the future. By calling date.query and passing a query that will check if a date is a weekend day, either Saturday or Sunday, if so adding 1 day into the future.


public class NinetyDayWeekendAdjuster implements TemporalAdjuster {

    public Temporal adjustInto(Temporal temporal) {

        LocalDateTime currentDateTime = LocalDateTime.from(temporal);

        LocalDateTime futureDate = LocalDateTime.from(temporal).plus(90,

        for (LocalDateTime startDate = currentDateTime; startDate
                .isBefore(futureDate); startDate = startDate.plusDays(1)) {

            if (startDate.query(new WeekendQuery())) {
                futureDate = futureDate.plusDays(1);
        return futureDate;

90 business days

public void test() {

    LocalDateTime currentDateTime = LocalDateTime.of(2014, Month.APRIL, 30,
            0, 0);

    LocalDateTime adjustedDate = currentDateTime
            .with(new NinetyDayWeekendAdjuster());

    assertEquals(LocalDateTime.of(2014, Month.SEPTEMBER, 3, 0, 0),