Example usage for java.time LocalDateTime isBefore

List of usage examples for java.time LocalDateTime isBefore

Introduction

In this page you can find the example usage for java.time LocalDateTime isBefore.

Prototype

@Override 
public boolean isBefore(ChronoLocalDateTime<?> other) 

Source Link

Document

Checks if this date-time is before the specified date-time.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2012, 6, 30, 12, 00);
    LocalDateTime b = LocalDateTime.of(2012, 7, 1, 12, 00);
    System.out.println(a.isBefore(b));
    System.out.println(a.isBefore(a));
}

From source file:ch.sbb.releasetrain.director.Director.java

private boolean laysInPast(LocalDateTime date) {
    return date.isBefore(LocalDateTime.now());
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Reads and parses the registration period.<br>
 * Validates the format and that the start is after the end.
 *
 * @return the {@link RegistrationPeriod}
 *//* www. j  a  va 2 s . co m*/
public static RegistrationPeriod readAndParseRegistrationDates() {
    LOG.info("Date need to be of the format 'yyyy-MM-ddTHH:mm'. E.g.: 2016-04-15T13:00"); // TODO get from the formatter
    LocalDateTime registrationStart = null, registrationEnd = null;
    boolean validStart = false, validEnd = false;

    Scanner scanner = new Scanner(System.in);
    while (!validStart) {
        LOG.info("Registration start: ");
        String line = StringUtils.deleteWhitespace(scanner.nextLine());
        try {
            registrationStart = LocalDateTime.parse(line, Defaults.DATE_FORMAT);
            validStart = true;
        } catch (DateTimeParseException dtpe) {
            LOG.error("'" + line + "' is not a valid date");
        }
    }

    while (!validEnd) {
        LOG.info("Registration end:  ");
        String line = scanner.nextLine();
        try {
            registrationEnd = LocalDateTime.parse(line, Defaults.DATE_FORMAT);
            validEnd = registrationStart.isBefore(registrationEnd);
            if (!validEnd) {
                LOG.error("End of registration has to be after the start'" + registrationStart + "'");
            }
        } catch (DateTimeParseException dtpe) {
            LOG.error("'" + line + "' is not a valid date");
        }
    }

    return new RegistrationPeriod(registrationStart, registrationEnd);
}

From source file:nu.yona.server.analysis.service.ActivityUpdateService.java

public void updateTimeExistingActivity(ActivityPayload payload, Activity existingActivity) {
    LocalDateTime startTimeLocal = payload.startTime.toLocalDateTime();
    if (startTimeLocal.isBefore(existingActivity.getStartTime())) {
        existingActivity.setStartTime(startTimeLocal);
    }//from w w w  .  j a  v a 2 s.  c  om
    LocalDateTime endTimeLocal = payload.endTime.toLocalDateTime();
    if (endTimeLocal.isAfter(existingActivity.getEndTime())) {
        existingActivity.setEndTime(endTimeLocal);
    }
}

From source file:edu.zipcloud.cloudstreetmarket.core.entities.Chart.java

public boolean isExpired(int ttlInMinutes) {
    Instant now = new Date().toInstant();
    LocalDateTime localNow = now.atZone(ZoneId.systemDefault()).toLocalDateTime();
    LocalDateTime localLastUpdate = DateUtils.addMinutes(lastUpdate, ttlInMinutes).toInstant()
            .atZone(ZoneId.systemDefault()).toLocalDateTime();
    return localLastUpdate.isBefore(localNow);
}

From source file:org.talend.dataprep.api.filter.SimpleFilterService.java

/**
 * Create a predicate that checks if the date value is within a range [min, max[
 *
 * @param columnId The column id//from w  ww. j  a  va2 s . c  om
 * @param start The start value
 * @param end The end value
 * @return The date range predicate
 */
private Predicate<DataSetRow> createDateRangePredicate(final String columnId, final String start,
        final String end, final RowMetadata rowMetadata) {
    try {
        final long minTimestamp = Long.parseLong(start);
        final long maxTimestamp = Long.parseLong(end);

        final LocalDateTime minDate = dateManipulator.fromEpochMillisecondsWithSystemOffset(minTimestamp);
        final LocalDateTime maxDate = dateManipulator.fromEpochMillisecondsWithSystemOffset(maxTimestamp);

        return safeDate(r -> {
            final ColumnMetadata columnMetadata = rowMetadata.getById(columnId);
            final LocalDateTime columnValue = getDateParser().parse(r.get(columnId), columnMetadata);
            return minDate.compareTo(columnValue) == 0
                    || (minDate.isBefore(columnValue) && maxDate.isAfter(columnValue));
        });
    } catch (Exception e) {
        LOGGER.debug("Unable to create date range predicate.", e);
        throw new IllegalArgumentException(
                "Unsupported query, malformed date 'range' (expected timestamps in min and max properties).");
    }
}