Example usage for java.time LocalDate isAfter

List of usage examples for java.time LocalDate isAfter

Introduction

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

Prototype

@Override 
public boolean isAfter(ChronoLocalDate other) 

Source Link

Document

Checks if this date is after the specified date.

Usage

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    System.out.println(tomorrow.isAfter(today));

}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDate yesterday = today.minus(1, DAYS);

    if (tomorrow.isAfter(today)) {
        System.out.println("Tomorrow comes after today");
    }/*from w  w  w .  j  a  v a  2 s  .  c  o  m*/

    if (yesterday.isBefore(today)) {
        System.out.println("Yesterday is day before today");
    }
}

From source file:Main.java

private static boolean stillInCalendar(YearMonth yearMonth, LocalDate day) {
    return !day.isAfter(yearMonth.atEndOfMonth());
}

From source file:mesclasses.util.NodeUtil.java

/**
 * vrifie si une date est entre les dates fournies (incluses)
 * @param date/*from   w  w w  .j  av  a  2  s.c o  m*/
 * @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: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   w w w.j  av a 2  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:com.intuit.wasabi.api.pagination.filters.impl.ExperimentFilter.java

/**
 * Tests dates for more sophisticated constraints than just partial string matches.
 * <p>/*  w  w w .  j  ava 2  s . 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:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    YearMonth requestedMonth = YearMonth.now();
    if (parameter.size() > 0) {
        requestedMonth = YearMonth.parse(Iterables.get(parameter, 0));
    }/*  w w w.j  a  va2 s  .c om*/
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime",
            "Overtime", "Comment"));
    Duration overtime = Duration.ZERO;
    LocalDate currentday = requestedMonth.atDay(1);
    while (!currentday.isAfter(requestedMonth.atEndOfMonth())) {
        Collection<Booking> currentBookings = getBookingsForDay(currentday);
        if (hasCompleteBookings(currentBookings)) {
            String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE);
            LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime();
            LocalTime endtime = Iterables.getLast(currentBookings).getEndtime();
            Duration presence = calculatePresence(starttime, endtime);
            Duration worktime = calculateWorktime(currentBookings);
            Duration breaktime = calculateBreaktime(presence, worktime);
            Duration currentOvertime = calculateOvertime(worktime, currentday);
            overtime = overtime.plus(currentOvertime);
            result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")),
                    endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence),
                    formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime),
                    validate(worktime, breaktime)));
        }
        currentday = currentday.plusDays(1);
    }
    return result;
}

From source file:example.app.model.Person.java

public void setBirthDate(LocalDate birthDate) {
    if (birthDate != null && birthDate.isAfter(LocalDate.now())) {
        throw new IllegalArgumentException(
                String.format("[%s] cannot be born after today [%s]", getName(), toString(LocalDate.now())));
    }/*from w w w.ja va2s .c o  m*/

    this.birthDate = birthDate;
}

From source file:io.syndesis.github.GitHubServiceImpl.java

@Override
public User getApiUser() throws IOException {
    final User user = userService.getUser();
    // if the user did not elect to publicly display his e-mail address, e-mail will be null
    // https://developer.github.com/v3/users/#get-a-single-user
    // let's put a dummy e-mail address then, as it is needed for the commit
    if (user.getEmail() == null) {
        // users before 2017-07-18 have their no-reply e-mail addresses in the form
        // username@users.noreply.github.com, and after that date
        // id+username@users.noreply.github.com
        // https://help.github.com/articles/about-commit-email-addresses/
        final LocalDate createdAt = user.getCreatedAt().toInstant().atZone(ZoneId.systemDefault())
                .toLocalDate();//w w  w  .  j  a va 2s.  c  o m
        if (createdAt.isAfter(GITHUB_NOREPLY_EMAIL_CUTOFF)) {
            user.setEmail(user.getId() + "+" + user.getLogin() + "@users.noreply.github.com");
        } else {
            user.setEmail(user.getLogin() + "@users.noreply.github.com");
        }
    }

    return user;
}

From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingServiceTypeCalendar.java

private void parseCalendarFile(final Reader calendarReader, final Multimap<LocalDate, String> serviceTypesMap)
        throws IOException {

    final CSVParser calendarParser = new CSVParser(calendarReader, CSVFormat.DEFAULT.withHeader());
    final List<CSVRecord> calendarRecords = calendarParser.getRecords();

    LocalDate earliestDate = null;
    LocalDate latestDate = null;//  w  ww.  j a va  2s  .  c o m
    for (final CSVRecord record : calendarRecords) {
        final String serviceType = record.get("service_id");

        final LocalDate start = LocalDate.parse(record.get("start_date"), DateTimeFormatter.BASIC_ISO_DATE);
        if (earliestDate == null || start.isBefore(earliestDate)) {
            earliestDate = start;
        }

        final LocalDate end = LocalDate.parse(record.get("end_date"), DateTimeFormatter.BASIC_ISO_DATE);
        if (latestDate == null || end.isAfter(latestDate)) {
            latestDate = end;
        }

        final EnumSet<DayOfWeek> daysOfWeek = EnumSet.noneOf(DayOfWeek.class);
        if (record.get("monday").equals("1")) {
            daysOfWeek.add(DayOfWeek.MONDAY);
        }
        if (record.get("tuesday").equals("1")) {
            daysOfWeek.add(DayOfWeek.TUESDAY);
        }
        if (record.get("wednesday").equals("1")) {
            daysOfWeek.add(DayOfWeek.WEDNESDAY);
        }
        if (record.get("thursday").equals("1")) {
            daysOfWeek.add(DayOfWeek.THURSDAY);
        }
        if (record.get("friday").equals("1")) {
            daysOfWeek.add(DayOfWeek.FRIDAY);
        }
        if (record.get("saturday").equals("1")) {
            daysOfWeek.add(DayOfWeek.SATURDAY);
        }
        if (record.get("sunday").equals("1")) {
            daysOfWeek.add(DayOfWeek.SUNDAY);
        }

        LocalDate targetDate = start;
        while (!targetDate.isAfter(end)) {
            if (daysOfWeek.contains(targetDate.getDayOfWeek())) {
                serviceTypesMap.put(targetDate, serviceType);
            }
            targetDate = targetDate.plusDays(1);
        }
    }
}