Example usage for java.time LocalDate isEqual

List of usage examples for java.time LocalDate isEqual

Introduction

In this page you can find the example usage for java.time LocalDate isEqual.

Prototype

@Override 
public boolean isEqual(ChronoLocalDate other) 

Source Link

Document

Checks if this date is equal to the specified date.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = LocalDate.of(2014, 7, 1);
    System.out.println(a.isEqual(b));
    System.out.println(a.isEqual(a));
    System.out.println(b.isEqual(a));
}

From source file:Main.java

public static void main(String[] args) {

    LocalDate today = LocalDate.now();
    LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

    LocalDate nextBDay = birthday.withYear(today.getYear());

    //If your birthday has occurred this year already, add 1 to the year.
    if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) {
        nextBDay = nextBDay.plusYears(1);
    }/*from ww w.ja  v a 2s .co  m*/

    Period p = Period.between(today, nextBDay);
    long p2 = ChronoUnit.DAYS.between(today, nextBDay);
    System.out.println("There are " + p.getMonths() + " months, and " + p.getDays()
            + " days until your next birthday. (" + p2 + " total)");
}

From source file:com.nridge.core.base.std.DatUtl.java

/**
 * Calculates the number of business days (excluding weekends)
 * between two dates (inclusive).  In addition, this utility
 * method will factor in holidays (e.g. skip them in the count)
 * for the calculation.//from  www. java2  s.  com
 * <p>
 * https://stackoverflow.com/questions/4600034/calculate-number-of-weekdays-between-two-dates-in-java
 * </p>
 *
 * @param aStartDate Start date.
 * @param anEndDate End date.
 * @param aHolidayList List of holidays to skip.
 *
 * @return Number of business days.
 */
public static long calculateBusinessDays(LocalDate aStartDate, LocalDate anEndDate,
        List<LocalDate> aHolidayList) {
    long totalBusinessDays = calculateBusinessDays(aStartDate, anEndDate);

    if ((totalBusinessDays > 0) && (aHolidayList != null)) {
        for (LocalDate holidayDate : aHolidayList) {
            if (holidayDate.isEqual(aStartDate))
                totalBusinessDays--;
            else if (holidayDate.isEqual(anEndDate))
                totalBusinessDays--;
            else if ((holidayDate.isAfter(aStartDate)) && (holidayDate.isBefore(anEndDate)))
                totalBusinessDays--;
        }
    }

    return Math.max(totalBusinessDays, 0);
}

From source file:mesclasses.util.NodeUtil.java

/**
 * vrifie si une date est entre les dates fournies (incluses)
 * @param date//from w w w .  j a  v a 2s .c om
 * @param start
 * @param end
 * @return 
 */
public static boolean isBetween(LocalDate date, LocalDate start, LocalDate end) {
    if (date == null || start == null || end == null) {
        return false;
    }
    return (date.isAfter(start) || date.isEqual(start)) && (date.isBefore(end) || date.isEqual(end));
}

From source file:io.manasobi.utils.DateUtils.java

/**
 * ? ? ?? ?  ?.<br><br>//from  ww  w.  java2  s  . c o  m
 *
 * DateUtils.equals(new LocalDate(1292252400000l), new LocalDate(1292252400000l)) = true
 *
 * @param date1 LocalDate? ??
 * @param date2 LocalDate? ??
 * @return ? ? ??  true  false .
 */
public static boolean equals(LocalDate date1, LocalDate date2) {
    return date1.isEqual(date2);
}

From source file:com.intuit.wasabi.api.pagination.filters.impl.ExperimentFilter.java

/**
 * Tests dates for more sophisticated constraints than just partial string matches.
 * <p>/*from  ww  w .  j  av  a  2s  .  c om*/
 * <p>
 * The a filter to check these constraints has to be of the following form:<br />
 * {@code is[any|on|before|after|between]:MM/dd/yyyy[:MM/dd/yyyy]}
 * <p>
 * For example to check whether the start date was before March 15, 2014 you would use a filter like:<br />
 * {@code date_constraint_start=isbefore:03/15/2014}
 * <p>
 * To check if an end date lies between (inclusive!) May 4, 2013 and July 4, 2014 you would use a
 * filter like:<br />
 * {@code date_constraint_end=isbetween:05/04/2013:07/04/2014}
 * <p>
 * Note that {@code isbetween} is the only value taking two dates and {@code isany} as well as empty strings
 * and {@code null} always return true.
 *
 * @param experimentDate the experiment date value to test
 * @param filter         the filter
 * @return true if the constraint is fulfilled
 */
/*test*/
static boolean constraintTest(Date experimentDate, String filter) {
    String[] extracted = FilterUtil.extractTimeZone(filter);
    String originalFilter = extracted[0];
    String timeZoneOffset = "+0000";
    try {
        timeZoneOffset = extracted[1];
    } catch (ArrayIndexOutOfBoundsException ignored) {
    }

    String[] structuredFilter = originalFilter.split(":");

    if (structuredFilter.length < 2) {
        if (StringUtils.isBlank(structuredFilter[0]) || structuredFilter[0].equalsIgnoreCase("isAny")) {
            return true;
        }
        throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format for constraint date ( "
                + filter + " ), " + "use: is[any|on|before|after|between]:MM/dd/yyyy[:MM/dd/yyyy]");
    }

    if (StringUtils.isBlank(structuredFilter[0])) {
        throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format for constraint date ( "
                + filter + " ), " + "needs one of is[any|on|before|after|between] before the colon.");
    }

    LocalDate experimentLocalDate = FilterUtil.convertDateToOffsetDateTime(experimentDate).toLocalDate();

    if (structuredFilter[0].equalsIgnoreCase("isBetween")) {
        try {
            LocalDate beforeExperimentDate = FilterUtil.parseUIDate(structuredFilter[1], timeZoneOffset)
                    .minusDays(1).toLocalDate();
            LocalDate afterExperimentDate = FilterUtil.parseUIDate(structuredFilter[2], timeZoneOffset)
                    .plusDays(1).toLocalDate();
            return experimentLocalDate.isAfter(beforeExperimentDate)
                    && experimentLocalDate.isBefore(afterExperimentDate);
        } catch (ArrayIndexOutOfBoundsException aioobe) {
            throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format for isBetween ( "
                    + filter + " ), " + "use: isbetween:MM/dd/yyyy:MM/dd/yyyy .", aioobe);
        }
    }

    LocalDate filterDate = FilterUtil.parseUIDate(structuredFilter[1], timeZoneOffset).toLocalDate();
    switch (structuredFilter[0].toLowerCase()) {
    case "isbefore":
        return experimentLocalDate.isBefore(filterDate);
    case "isafter":
        return experimentLocalDate.isAfter(filterDate);
    case "ison":
        return experimentLocalDate.isEqual(filterDate);
    }
    throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE,
            "Wrong format: not processable filter format ( " + filter + " ).");
}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void updateSessionDate() {
    final SessionEditor editor = getEditor();
    final Session session = editor.getDataModel().getSession();

    final LocalDate currentDate = session.getDate();
    final LocalDate newDate = LocalDate.from(dateField.getDateTime());

    if (!currentDate.isEqual(newDate)) {
        final SessionDateEdit edit = new SessionDateEdit(getEditor(), newDate, currentDate);
        edit.setSource(dateField);/*  w w  w  .  j a  va  2  s .  co  m*/
        editor.getUndoSupport().postEdit(edit);
    }

}

From source file:org.silverpeas.core.date.Period.java

/**
 * Creates a new period of time between the two non null specified dates. The period is spreading
 * over all the day(s) between the specified inclusive start day and the exclusive end day; the
 * period is expressed in days. For example, a period between 2016-12-15 and 2016-12-17 means the
 * period is spreading over two days (2016-12-15 and 2016-12-16).
 * @param startDay the start day of the period. It defines the inclusive date at which the
 * period starts./*from   ww w  .  j a  v  a 2  s.  com*/
 * @param endDay the end day of the period. It defines the exclusive date at which the period
 * ends. The end date must be the same or after the start date. An end date equal to the start
 * date means the period is spanning all the day of the start date; it is equivalent to an end
 * date being one day after the start date.
 * @return the period of days between the two specified dates.
 */
public static Period between(LocalDate startDay, LocalDate endDay) {
    checkPeriod(startDay, endDay);
    Period period = new Period();
    period.startDateTime = startDay == LocalDate.MIN ? OffsetDateTime.MIN
            : startDay.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime();
    period.endDateTime = endDay == LocalDate.MAX ? OffsetDateTime.MAX
            : endDay.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime();
    if (startDay.isEqual(endDay)) {
        period.endDateTime = period.endDateTime.plusDays(1);
    }
    period.inDays = true;
    return period;
}