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:com.romeikat.datamessie.core.statistics.service.StatisticsService.java

public <T> SparseSingleTable<Long, LocalDate, T> getStatistics(final StatisticsSparseTable baseStatistics,
        final Collection<Long> sourceIds, final LocalDate from, final LocalDate to,
        final Function<LocalDate, LocalDate> transformDateFunction,
        final Function<DocumentsPerState, T> transformValueFunction) {
    final MergeNumberOfDocumentsFunction mergeNumberOfDocumentsFunction = new MergeNumberOfDocumentsFunction();
    final ITableExtractor<Long, LocalDate, DocumentsPerState, T> tableExtractor = new ITableExtractor<Long, LocalDate, DocumentsPerState, T>() {

        @Override/*from  ww w. j ava  2  s.c o  m*/
        public Long getExtractedRowHeader(final Long sourceId) {
            if (sourceIds.contains(sourceId)) {
                return sourceId;
            }
            return null;
        }

        @Override
        public LocalDate getExtractedColumnHeader(final LocalDate publishedDate) {
            if (from != null && publishedDate.isBefore(from)) {
                return null;
            }
            if (to != null && publishedDate.isAfter(to)) {
                return null;
            }

            final LocalDate transformedPublishedDate = transformDateFunction.apply(publishedDate);
            return transformedPublishedDate;
        }

        @Override
        public DocumentsPerState mergeValues(final DocumentsPerState documentsPerState1,
                final DocumentsPerState documentsPerState2) {
            return mergeNumberOfDocumentsFunction.apply(new ImmutablePair<DocumentsPerState, DocumentsPerState>(
                    documentsPerState1, documentsPerState2));
        }

        @Override
        public T getExtractedValue(final DocumentsPerState documentsPerState) {
            return transformValueFunction.apply(documentsPerState);
        }

    };

    final SparseSingleTable<Long, LocalDate, T> extractedStatistics = baseStatistics.extract(tableExtractor);

    // extractedStatistics only contains row headers for source IDs that were reported within the
    // time period; in order to cover all source IDs, we add all (remaining) source IDs
    extractedStatistics.addRowHeaders(sourceIds);

    // extractedStatistics only contains column headers for dates that were reported within the time
    // period; in order to cover all dates, we add all (remaining) dates
    final List<LocalDate> publishedDates = DateUtil.getLocalDatesBetween(from, to);
    final List<LocalDate> transformedPublishedDates = Lists.transform(publishedDates, transformDateFunction);
    extractedStatistics.addColumnHeaders(transformedPublishedDates);

    return extractedStatistics;
}

From source file:com.romeikat.datamessie.core.base.service.DocumentService.java

private LocalDate getNextDownloadedDate(final LocalDate downloadedDate) {
    // Increase only up to current date
    final LocalDate now = LocalDate.now();
    if (downloadedDate.isAfter(now)) {
        return null;
    }//from w w  w.ja  v a2s . co m
    // Otherwise, go to next date
    return downloadedDate.plusDays(1);
}

From source file:com.github.drbookings.ui.controller.UpcomingController.java

private void addEvents(final LocalDate date, final Collection<BookingEntry> upcomingBookings,
        final Collection<CleaningEntry> upcomingCleanings) {
    final VBox box = new VBox(4);
    if (date.equals(LocalDate.now())) {
        box.getStyleClass().add("first-day");
    } else if (date.equals(LocalDate.now().plusDays(1))) {
        box.getStyleClass().add("second-day");
    } else if (date.isAfter(LocalDate.now().plusDays(1))) {
        box.getStyleClass().add("later");
    }//from  w  w w  .j  a  v a 2  s  .c  o m

    if (upcomingBookings.stream().filter(b -> b.isCheckIn() || b.isCheckOut()).collect(Collectors.toList())
            .isEmpty() && upcomingCleanings.isEmpty()) {
        final Text t0 = new Text(getDateString(date));
        final Text t1 = new Text(" there are no events.");
        t0.getStyleClass().add("emphasis");
        final TextFlow tf = new TextFlow();
        tf.getChildren().addAll(t0, t1);
        box.getChildren().addAll(tf);
    } else {
        final List<CheckInOutDetails> checkInNotes = Collections.synchronizedList(new ArrayList<>());
        final List<CheckInOutDetails> checkOutNotes = Collections.synchronizedList(new ArrayList<>());
        upcomingBookings.forEach(b -> {
            if (b.isCheckIn()) {
                String note = "";
                if (b.getElement().getCheckInNote() != null) {
                    note = b.getElement().getCheckInNote();
                }
                if (b.getElement().getSpecialRequestNote() != null) {
                    note = note + "\n" + b.getElement().getSpecialRequestNote();
                }
                checkInNotes.add(new CheckInOutDetails(b.getRoom().getName(),
                        b.getElement().getBookingOrigin().getName(), note));
            } else if (b.isCheckOut()) {
                checkOutNotes.add(new CheckInOutDetails(b.getRoom().getName(),
                        b.getElement().getBookingOrigin().getName(), b.getElement().getCheckOutNote()));
            }
        });
        Collections.sort(checkInNotes);
        Collections.sort(checkOutNotes);
        addGeneralSummary(date, box, checkInNotes);
        addCheckOutSummary(date, box, checkOutNotes);
        addCheckOutNotes(date, box, checkOutNotes);
        addCheckInSummary(date, box, checkInNotes);
        addCheckInNotes(date, box, checkInNotes);
        addCleaningSummary(date, box, upcomingCleanings);
        addCleanings(date, box, upcomingCleanings);
    }

    this.box.getChildren().add(box);

}

From source file:memoryaid.SetReminderController.java

@FXML
private void handleSetReminderBtnAction(ActionEvent event) throws Exception {

    System.out.println("You clicked Add Reminder!");

    String rType = (String) reminderTypeBox.getValue();
    String rName = reminderNameText.getText();
    LocalDate rSDate = startDateId.getValue();
    LocalDate rEDate = endDateId.getValue();
    List<LocalDate> reminderDates = new ArrayList<>();

    String hours = (String) reminderHhBox.getValue();
    String minutes = (String) reminderMmBox.getValue();
    String seconds = (String) reminderSsBox.getValue();
    ObservableList<String> repeat = multiSelectComboBox.getCheckModel().getCheckedItems();

    String imgPath = imagePathText.getText();

    if (rType == null || rName == null || rSDate == null || rEDate == null || hours == null || minutes == null
            || seconds == null || repeat.size() == 0 || imgPath == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Dialog");
        alert.setHeaderText("Oops, an Error Dialog");
        alert.setContentText("Please fill all the fields");
        alert.showAndWait();//w  w w.j  ava 2 s. c o m
        System.out.println("Please fill all the fields");
    } else if (rSDate.isAfter(rEDate) == true) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Error Dialog");
        alert.setHeaderText("Oops, an Error Dialog");
        alert.setContentText("End date cannot be before the Start date");
        alert.showAndWait();
        System.out.println("End date should be greater than start date");
    } else {
        String rTime = hours + ":" + minutes + ":" + seconds;
        if (rType != null && rName != null && !rName.isEmpty() && rEDate != null && hours != null
                && minutes != null && seconds != null && repeat != null && imgPath != null) {

            String destinationPath = "/Users/madhaviunnam/NetBeansProjects/MemoryAid/src/Reminders";
            File destinationPathObject = new File(destinationPath + "/" + rName + ".png");
            File sourceFilePathObject = new File(imgPath);
            FileUtils.copyFile(sourceFilePathObject, destinationPathObject);

            System.out.println(
                    "You clicked Add Reminder!" + rType + rName + rSDate + rEDate + rTime + repeat + imgPath);
            System.out.println("****Inside if");
            Reminder reminderToSet = new Reminder();
            reminderToSet.setReminderName(rName);
            reminderToSet.setReminderType(rType);
            reminderToSet.setStartDate(rSDate);
            reminderToSet.setEndDate(rEDate);

            //endDateToCheck = rEDate.plusDays(1);

            if (repeat.contains("Every Monday")) {
                reminderToSet.setRepeatMon("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.MONDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatMon("false");
            }
            if (repeat.contains("Every Tuesday")) {
                reminderToSet.setRepeatTue("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.TUESDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatTue("false");
            }
            if (repeat.contains("Every Wednesday")) {
                reminderToSet.setRepeatWed("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.WEDNESDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatWed("false");
            }
            if (repeat.contains("Every Thursday")) {
                reminderToSet.setRepeatThu("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.THURSDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatThu("false");
            }
            if (repeat.contains("Every Friday")) {
                reminderToSet.setRepeatFri("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.FRIDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatFri("false");
            }
            if (repeat.contains("Every Saturday")) {
                reminderToSet.setRepeatSat("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.SATURDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
                rSDate = startDateId.getValue();
            } else {
                reminderToSet.setRepeatSat("false");
            }
            if (repeat.contains("Every Sunday")) {
                reminderToSet.setRepeatSun("true");
                while (rSDate.isBefore(rEDate)) {
                    if (rSDate.getDayOfWeek() == DayOfWeek.SUNDAY) {
                        reminderDates.add(rSDate);
                    }
                    rSDate = rSDate.plusDays(1);
                }
            } else {
                reminderToSet.setRepeatSun("false");
            }
            if (repeat.contains("None")) {
                reminderToSet.setRepeatNone("true");
                reminderDates.add(rSDate);
            } else {
                reminderToSet.setRepeatNone("false");
            }

            System.out.println("%%%%Reminder DATes" + reminderDates);
            reminderToSet.setReminderTime(rTime);
            reminderToSet.setReminderStatus("New");

            DbConnection db = new DbConnection();
            Connection conn = db.connect();
            PreparedStatement preparedStmt = null;
            String insertSql = "INSERT into Reminders(ReminderType, ReminderName, StartDate, EndDate, ReminderTime, RepeatM, RepeatT, RepeatW, RepeatTH, RepeatF, RepeatSat, RepeatSun)"
                    + "values(?,?,?,?,?,?,?,?,?,?,?,?)";
            preparedStmt = conn.prepareStatement(insertSql);
            preparedStmt.setString(1, reminderToSet.getReminderType());
            preparedStmt.setString(2, reminderToSet.getReminderName());
            preparedStmt.setString(3, reminderToSet.getStartDate().toString());
            preparedStmt.setString(4, reminderToSet.getEndDate().toString());
            preparedStmt.setString(5, reminderToSet.getReminderTime());
            preparedStmt.setString(6, reminderToSet.getRepeatMon());
            preparedStmt.setString(7, reminderToSet.getRepeatTue());
            preparedStmt.setString(8, reminderToSet.getRepeatWed());
            preparedStmt.setString(9, reminderToSet.getRepeatThu());
            preparedStmt.setString(10, reminderToSet.getRepeatFri());
            preparedStmt.setString(11, reminderToSet.getRepeatSat());
            preparedStmt.setString(12, reminderToSet.getRepeatSun());

            preparedStmt.executeUpdate();
            System.out.println("Reminder Inserted Successfully  ");
            //Get the inserted reminders RId
            String getRIdsql = "Select max(RId) as RId from Reminders";
            ResultSet rSet = conn.createStatement().executeQuery(getRIdsql);
            int newRId = 0;
            while (rSet.next()) {
                newRId = rSet.getInt(1);

            }
            System.out.println("RID ^^^^^^^^" + newRId);
            PreparedStatement preparedStmtRDetails = null;
            for (int i = 0; i < reminderDates.size(); i++) {
                String rDetailsSql = "Insert into ReminderDetails(RId,DetailNum,ReminderDate,ReminderStatus)"
                        + " values(?,?,?,?)";
                preparedStmtRDetails = conn.prepareStatement(rDetailsSql);
                preparedStmtRDetails.setInt(1, newRId);
                preparedStmtRDetails.setInt(2, i);
                preparedStmtRDetails.setString(3, reminderDates.get(i).toString());
                preparedStmtRDetails.setString(4, "New");
                preparedStmtRDetails.executeUpdate();
                System.out.println("ReminderDetails Table Insert Successfull  ");
            }
            Parent setReminder = FXMLLoader.load(getClass().getResource("SetReminder.fxml"));
            Scene set_reminder_refresh_scene = new Scene(setReminder);
            Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
            app_stage.hide();
            app_stage.setScene(set_reminder_refresh_scene);
            app_stage.show();

        } else {
            System.out.println("Inside else");
            //show alert
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error Dialog");
            alert.setHeaderText("Oops, an Error Dialog");
            alert.setContentText("Please fill all the fields");
            alert.showAndWait();

        }
    }

}

From source file:no.imr.stox.functions.utils.CovariateUtils.java

public static Boolean isInPeriod(LocalDate date, String period) {
    if (date == null || period == null) {
        return false;
    }//  w  w w  . j  a v a  2s.  c o m
    String[] s = period.split("-");
    if (s.length == 2) {
        Integer year = date.getYear();
        LocalDate from = IMRdate.strToLocalDate(getFullPeriod(s[0], year), IMRdate.DATE_FORMAT_DMY);
        LocalDate to = IMRdate.strToLocalDate(getFullPeriod(s[1], year), IMRdate.DATE_FORMAT_DMY);
        if (IMRdate.isSameDay(date, from) || IMRdate.isSameDay(date, to)
                || date.isAfter(from) && date.isBefore(to)) {
            return true;
        }
    }
    return false;
}

From source file:org.jboss.jbossset.CommandLineParser.java

private LocalDate getValidLocalDate(String date, String optionName) throws ParseException {
    try {//from www . j a v  a2s. c  o m
        LocalDate localDate = LocalDate.parse(date);
        if (optionName.equals("startDate") && localDate.isAfter(LocalDate.now()))
            throw new ParseException("startDate cannot be in the future.");
        return localDate;
    } catch (DateTimeParseException e) {
        throw new ParseException("Invalid " + optionName + ". Date format must be YYYY-MM-DD.");
    }
}

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

private static void checkPeriod(final LocalDate startDate, final LocalDate endDate) {
    Objects.requireNonNull(startDate);
    Objects.requireNonNull(endDate);
    if (startDate.isAfter(endDate)) {
        throw new IllegalArgumentException("The end date must be after or equal to the start date");
    }//from  w  w  w .  j av a 2 s.  c  o  m
}

From source file:org.tightblog.util.Utilities.java

/**
 * Parse date as either 6-char or 8-char format.  Use current date if date not provided
 * in URL (e.g., a permalink), more than 30 days in the future, or not valid
 *//*from   ww w. j  av a  2s.  co  m*/
public static LocalDate parseURLDate(String dateString) {
    LocalDate ret = null;

    try {
        if (StringUtils.isNumeric(dateString)) {
            if (dateString.length() == 8) {
                ret = LocalDate.parse(dateString, Utilities.YMD_FORMATTER);
            } else if (dateString.length() == 6) {
                YearMonth tmp = YearMonth.parse(dateString, Utilities.YM_FORMATTER);
                ret = tmp.atDay(1);
            }
        }
    } catch (DateTimeParseException ignored) {
        ret = null;
    }

    // make sure the requested date is not more than a month in the future
    if (ret == null || ret.isAfter(LocalDate.now().plusDays(30))) {
        ret = LocalDate.now();
    }

    return ret;
}

From source file:serposcope.controllers.admin.DebugController.java

@FilterWith(XSRFFilter.class)
public Result dryRun(Context context, @Param("startDate") String start, @Param("endDate") String end) {
    long _start = System.currentTimeMillis();
    FlashScope flash = context.getFlashScope();

    LocalDate startDate = null;
    LocalDate endDate = null;//from  ww w. j a v a2 s.c  om

    try {
        startDate = LocalDate.parse(start);
        endDate = LocalDate.parse(end);
    } catch (Exception ex) {
    }

    if (startDate == null || endDate == null || startDate.isAfter(endDate)) {
        flash.error("error.invalidDate");
        return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    Run lastRun = baseDB.run.findLast(Module.GOOGLE, null, null);
    if (lastRun != null && lastRun.getDay().isAfter(startDate)) {
        flash.error("error.invalidDate");
        return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    LocalDate date = LocalDate.from(startDate);

    GoogleSettings ggOptions = googleDB.options.get();

    int minPauseBetweenPageSec = ggOptions.getMinPauseBetweenPageSec();
    int maxPauseBetweenPageSec = ggOptions.getMaxPauseBetweenPageSec();
    ggOptions.setMinPauseBetweenPageSec(0);
    ggOptions.setMaxPauseBetweenPageSec(0);
    googleDB.options.update(ggOptions);

    try {
        while (date.isBefore(endDate)) {
            LOG.debug("dry run {}", date);
            if (!taskManager
                    .startGoogleTask(new Run(Run.Mode.MANUAL, Module.GOOGLE, date.atTime(13, 37, 00)))) {
                LOG.error("can't startGoogleTask");
                flash.error("can't startGoogleTask");
                return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
            }
            taskManager.joinGoogleTask();
            date = date.plusDays(1);
        }
    } catch (Exception ex) {
        LOG.error("an error occured", ex);
        flash.error("an error occured");
        return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    } finally {
        ggOptions.setMinPauseBetweenPageSec(minPauseBetweenPageSec);
        ggOptions.setMaxPauseBetweenPageSec(maxPauseBetweenPageSec);
        googleDB.options.update(ggOptions);
    }

    LOG.debug("dry run timing : {}",
            DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - _start));
    flash.success("ok");
    return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
}