Example usage for java.time LocalDate isBefore

List of usage examples for java.time LocalDate isBefore

Introduction

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

Prototype

@Override 
public boolean isBefore(ChronoLocalDate other) 

Source Link

Document

Checks if this date is before the specified date.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    VBox vbox = new VBox(20);
    Scene scene = new Scene(vbox, 400, 400);
    stage.setScene(scene);/* w  ww  .j  av a  2s  . co m*/
    DatePicker startDatePicker = new DatePicker();
    DatePicker endDatePicker = new DatePicker();
    startDatePicker.setValue(LocalDate.now());
    final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
        @Override
        public DateCell call(final DatePicker datePicker) {
            return new DateCell() {
                @Override
                public void updateItem(LocalDate item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item.isBefore(startDatePicker.getValue().plusDays(1))) {
                        setDisable(true);
                        setStyle("-fx-background-color: #EEEEEE;");
                    }
                }
            };
        }
    };
    endDatePicker.setDayCellFactory(dayCellFactory);
    endDatePicker.setValue(startDatePicker.getValue().plusDays(1));
    vbox.getChildren().add(new Label("Start Date:"));
    vbox.getChildren().add(startDatePicker);
    vbox.getChildren().add(new Label("End Date:"));
    vbox.getChildren().add(endDatePicker);
    stage.show();
}

From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsController.java

public boolean clearReports(LocalDate date) {
    try {//ww  w  .  j a  v  a 2 s .  co  m
        File reports = new File(DPFManagerProperties.getReportsDir());
        for (File folder : reports.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY)) {
            LocalDate folderDate = parseFolderName(folder.getName());
            if (folderDate != null && folderDate.isBefore(date)) {
                FileUtils.deleteDirectory(folder);
            }
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.tudresden.ecatering.model.stock.Ingredient.java

protected Ingredient(String name, Money price, Quantity quantity, LocalDate expirationDate) {

    super(new Product(name, price, quantity.getMetric()), quantity);

    if (expirationDate != null)
        if (expirationDate.isBefore(LocalDate.now()))
            throw new IllegalArgumentException("expirationDate already expired");

    this.expirationDate = expirationDate;
}

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//  w w w  .  j  a  va 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:example.complete.Customer.java

Customer(String firstname, String lastname, LocalDate birthday) {

    Assert.hasText(firstname, "Firstname must not be null or empty!");
    Assert.hasText(lastname, "Lastname must not be null or empty!");
    Assert.isTrue(birthday.isBefore(LocalDate.now()), "Date of birth must be in the past!");

    this.firstname = firstname;
    this.lastname = lastname;
    this.birthday = birthday;
}

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;/*from  w w  w . j av  a  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);
        }
    }
}

From source file:com.fantasy.stataggregator.workers.GameDataRetrieverTask.java

/**
 * Determines if a game has already been played, No current game data<br>
 * will be pulled, since the statistics aren't final.
 *
 * @param sched/*from  ww  w.  j av  a  2 s  . c  o m*/
 * @return
 */
private boolean hasBeenPlayed(GameSchedule sched) throws ParseException {
    Date gameDate = sched.getGamedate();
    if (Objects.nonNull(gameDate)) {
        LocalDate dateOnly = LocalDateTime.ofInstant(gameDate.toInstant(), ZoneId.systemDefault())
                .toLocalDate();

        return dateOnly.isBefore(LocalDate.now());
    }
    return false;
}

From source file:com.romeikat.datamessie.core.processing.task.documentProcessing.DocumentsProcessingTask.java

private LocalDate getNextDownloadedDate(final LocalDate downloadedDate) {
    // If download date is current date (or future), remain at current date
    final LocalDate now = LocalDate.now();
    if (!downloadedDate.isBefore(now)) {
        return now;
    }/*from  w ww.  ja va2  s . co  m*/
    // Otherwise, go to next date
    return downloadedDate.plusDays(1);
}

From source file:com.gigglinggnus.controllers.ManageExamsController.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EntityManager em = (EntityManager) request.getSession().getAttribute("em");

    Clock clk = (Clock) (request.getSession().getAttribute("clock"));

    List<Term> terms = Term.getFutureTerms(em, Instant.now(clk));
    List<Exam> exams = terms.stream().flatMap(term -> term.getExams().stream())
            .filter(exam -> exam.getStatus() == ExamStatus.PENDING).collect(Collectors.toList());

    Map<Exam, ArrayList<String>> utilMap = new HashMap();
    for (Exam e : exams) {
        Interval<Instant> examInt = e.getInterval();

        LocalDate testDate = examInt.getStart().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate endDate = examInt.getEnd().atZone(ZoneId.systemDefault()).toLocalDate();

        Term t = e.getTerm();/* w w w  . ja  va 2s  .c  om*/
        Map<LocalDate, Long> examUtilMap = new HashMap();
        ArrayList<String> examList = new ArrayList();
        while (testDate.isBefore(endDate.plusDays(1))) {

            examList.add(testDate.toString() + "=" + t.utilizationForDay(testDate, clk) + "   ");

            testDate = testDate.plusDays(1);
        }
        utilMap.put(e, examList);

    }

    request.setAttribute("exams", exams);
    request.setAttribute("utilList", utilMap);
    RequestDispatcher rd = request.getRequestDispatcher("/admin/manage-exams.jsp");
    rd.forward(request, response);
}

From source file:ec.edu.chyc.manejopersonal.managebean.GestorConvenio.java

public String guardar() {

    convenio.setProyectosCollection(new HashSet(listaProyectos));

    if (convenio.getProyectosCollection().isEmpty()) {
        GestorMensajes.getInstance().mostrarMensajeWarn("Por favor, agregar proyectos al convenio.");
        return "";
    }//  w w  w .j  ava2s .  c o  m

    if (convenio.getFechaInicio() != null && convenio.getFechaFin() != null) {
        LocalDate dtInicio = FechaUtils.asLocalDate(convenio.getFechaInicio());
        LocalDate dtFin = FechaUtils.asLocalDate(convenio.getFechaFin());
        //MutableDateTime dtInicio = new MutableDateTime(convenio.getFechaInicio());
        //MutableDateTime dtFin = new MutableDateTime(convenio.getFechaFin());

        if (dtFin.isBefore(dtInicio)) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error",
                    "La fecha de finalizacin debe ser mayor a la de inicio.");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            return "";
        }
    }

    try {
        if (modoModificar) {
            convenioController.edit(convenio);
        } else {
            convenioController.create(convenio);
        }
        return initListarConvenios();
        //return "listaConvenios";
    } catch (Exception ex) {
        Logger.getLogger(GestorConvenio.class.getName()).log(Level.SEVERE, null, ex);
    }

    return "";
}