Java LocalDateTime Calculate isWithin(LocalDateTime start, LocalDateTime end)

Here you can find the source of isWithin(LocalDateTime start, LocalDateTime end)

Description

Returns a Predicate that returns true if a LocalDateTime is between two others.

License

Apache License

Parameter

Parameter Description
start Start time
end End time <p>

Exception

Parameter Description
IllegalArgumentException if start is not before end

Return

predicate

Declaration

public static Predicate<LocalDateTime> isWithin(LocalDateTime start, LocalDateTime end) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.time.LocalDateTime;

import java.util.function.Predicate;

public class Main {
    /**//  www  .  j a v  a  2 s  .  c  o  m
     * Returns a {@link Predicate} that returns true if a {@link LocalDateTime} is between two others.
     * <p>
     * @param start Start time
     * @param end   End time
     * <p>
     * @return predicate
     * <p>
     * @throws IllegalArgumentException if start is not before end
     */
    public static Predicate<LocalDateTime> isWithin(LocalDateTime start, LocalDateTime end) {
        if (!start.isBefore(end)) {
            throw new IllegalArgumentException("Start " + start + " must be before end " + end);
        }

        return dt -> !dt.isBefore(start) && dt.isBefore(end);
    }
}

Related

  1. isAfterNow(LocalDateTime pValidUntil)
  2. isBefore(LocalDateTime dateTime1, LocalDateTime dateTime2)
  3. isOverdue(LocalDateTime dueTime)
  4. isToday(LocalDateTime dateTime)
  5. isTodayOrYesterday(LocalDateTime date)
  6. last(LocalDateTime from, int dayOfWeek)
  7. localDateTime2LocalDate(LocalDateTime localDateTime)
  8. ms2LocalDateTime(final long ms)
  9. oldDateToISO8601LocalDateTime(Date nextColumnDate)