Example usage for org.joda.time LocalDate now

List of usage examples for org.joda.time LocalDate now

Introduction

In this page you can find the example usage for org.joda.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:es.usc.citius.servando.calendula.util.PickupUtils.java

License:Open Source License

public Pair<LocalDate, List<PickupInfo>> getBestDay() {

    if (this.bestDay != null) {
        return this.bestDay;
    }/*from w w w . j a v  a  2  s. com*/

    HashMap<LocalDate, List<PickupInfo>> bestDays = new HashMap<>();
    if (pickups.size() > 0) {
        LocalDate today = LocalDate.now();
        LocalDate first = LocalDate.now();
        LocalDate now = LocalDate.now().minusDays(MAX_DAYS);

        if (now.getDayOfWeek() == DateTimeConstants.SUNDAY) {
            now = now.plusDays(1);
        }

        // get the date of the first med we can take from 10 days ago
        for (PickupInfo p : pickups) {
            if (p.from().isAfter(now) && !p.taken()) {
                first = p.from();
                break;
            }
        }

        for (int i = 0; i < 10; i++) {
            LocalDate d = first.plusDays(i);
            if (!d.isAfter(today) && d.getDayOfWeek() != DateTimeConstants.SUNDAY) {
                // only take care of days after today that are not sundays
                continue;
            }

            // compute the number of meds we cant take for each day
            for (PickupInfo p : pickups) {
                // get the pickup take secure interval
                DateTime iStart = p.from().toDateTimeAtStartOfDay();
                DateTime iEnd = p.from().plusDays(MAX_DAYS - 1).toDateTimeAtStartOfDay();
                Interval interval = new Interval(iStart, iEnd);
                // add the pickup to the daily list if we can take it
                if (!p.taken() && interval.contains(d.toDateTimeAtStartOfDay())) {
                    if (!bestDays.containsKey(d)) {
                        bestDays.put(d, new ArrayList<PickupInfo>());
                    }
                    bestDays.get(d).add(p);
                }
            }
        }

        // select the day with the highest number of meds
        int bestDayCount = 0;
        LocalDate bestOption = null;
        Set<LocalDate> localDates = bestDays.keySet();
        ArrayList<LocalDate> sorted = new ArrayList<>(localDates);
        Collections.sort(sorted);
        for (LocalDate day : sorted) {
            List<PickupInfo> pks = bestDays.get(day);
            Log.d("PickupUtils", day.toString("dd/MM/YYYY") + ": " + pks.size());
            if (pks.size() >= bestDayCount) {
                bestDayCount = pks.size();
                bestOption = day;
                if (bestOption.getDayOfWeek() == DateTimeConstants.SUNDAY) {
                    bestOption = bestOption.minusDays(1);
                }
            }
        }
        if (bestOption != null) {
            this.bestDay = new Pair<>(bestOption, bestDays.get(bestOption));
            return this.bestDay;
        }
    }

    return null;
}

From source file:eu.edisonproject.classification.prepare.model.Date.java

License:Apache License

public Date() {
    date = LocalDate.now();
}

From source file:eu.trentorise.game.sample.DemoGameFactory.java

License:Apache License

private String generateCronExp() {
    // sample 0 2 0 4 JUN ? *
    LocalDate now = LocalDate.now();

    return String.format("0 0 0 %s %s ? %s", now.getDayOfMonth() - 1, now.getMonthOfYear(), now.getYear());
}

From source file:eu.uqasar.util.ModelInitializer.java

License:Apache License

/**
 *
 * @return//  ww w .  ja v  a2  s.  c  o  m
 */
private Product[] createProducts() {
    Product product1 = new Product("U-QASAR Test Product");
    product1.setDescription("Test product");
    product1.setVersion("0.1");
    int monthOffset = 6;
    int day = LocalDate.now().plusMonths(monthOffset).dayOfMonth().getMaximumValue();
    product1.setReleaseDate(DateTime.now().plusMonths(monthOffset).withDayOfMonth(day).toDate());
    product1 = productService.create(product1);

    return new Product[] { product1 };
}

From source file:eu.uqasar.web.components.historical.SnapshotSaveConfirmationModal.java

License:Apache License

public SnapshotSaveConfirmationModal(String id, final IModel<String> projectNameModel) {
    super(id);//from w  w  w .j  ava 2  s  .  c  o  m

    add(snapNameTextField = new TextField<>("textfield", projectNameModel));

    this.snapNameTextField.add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 6936801286109166680L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(submitButton);
        }

    });

    add(new Label("message", new StringResourceModel("snapshot.confirmation.modal.message", this, null)));

    header(new StringResourceModel("snapshot.confirmation.modal.header", this, null));

    add(new Label("timestamp", LocalDate.now().toString()));

    addButton(submitButton = new ModalActionButton(this, Buttons.Type.Info,
            new StringResourceModel("button.snapshot.confirm", this, null), true) {
        private static final long serialVersionUID = 5342016192194431918L;

        @Override
        protected void onConfigure() {
            super.onConfigure();

            if (snapNameTextField.getModelObject() == null || snapNameTextField.getModelObject().isEmpty()) {
                setEnabled(false);
            } else {
                setEnabled(true);
            }
        }

        @Override
        protected void onAfterClick(AjaxRequestTarget target) {
            onConfirmed(target);
            closeDeleteConfirmationModal(SnapshotSaveConfirmationModal.this, target);
        }
    });

    addButton(new ModalActionButton(this, Buttons.Type.Default,
            new StringResourceModel("button.snapshot.cancel", this, null), true) {
        private static final long serialVersionUID = 4299345298752864106L;

        @Override
        protected void onAfterClick(AjaxRequestTarget target) {
            closeDeleteConfirmationModal(SnapshotSaveConfirmationModal.this, target);
        }
    });

}

From source file:eu.uqasar.web.pages.BasePage.java

License:Apache License

private void setFooterYear() {
    LocalDate date = LocalDate.now();
    Label footer = new Label("footer", new StringResourceModel("footer.text", this, null, date.getYear()));
    footer.setEscapeModelStrings(false);
    add(footer);/*from   w w  w.  ja  v a 2  s  .  co m*/
}

From source file:fixture.simple.AlumnosFixture.java

License:Apache License

@Override
protected void execute(ExecutionContext executionContext) {

    // prereqs/*from  ww w. j av  a2s .  c  o  m*/
    execute(new GenericTearDownFixture("Alumno"), executionContext);

    int Cantidad = 20;

    // create
    for (int x = 0; x <= Cantidad; x++) {
        create(GenericData.ObtenerNombre(), GenericData.ObtenerApellido(), Persona.E_sexo.MASCULINO,
                GenericData.Random(10000000, 88888888), LocalDate.now(), Persona.E_nacionalidad.ARGENTINA,
                Localidad.E_localidades.NEUQUEN, GenericData.ObtenerCalle(), GenericData.Random(1, 9999), null,
                null, String.valueOf(GenericData.Random(10000000, 88888888)), executionContext);
    }
}

From source file:fixture.simple.PersonalFixture.java

License:Apache License

@Override
protected void execute(ExecutionContext executionContext) {

    // prereqs/*from w  w  w . j  a v  a  2 s  .  co m*/
    execute(new GenericTearDownFixture("Personal"), executionContext);

    int Cantidad = 20;

    // create
    for (int x = 0; x <= Cantidad; x++) {
        create(GenericData.ObtenerNombre(), GenericData.ObtenerApellido(), Persona.E_sexo.MASCULINO,
                GenericData.Random(10000000, 88888888), LocalDate.now(), Persona.E_nacionalidad.ARGENTINA,
                Localidad.E_localidades.NEUQUEN, GenericData.ObtenerCalle(), GenericData.Random(1, 9999), null,
                null, String.valueOf(GenericData.Random(10000000, 88888888)), executionContext);
    }
}

From source file:fr.xebia.extras.selma.it.custom.interceptor.beans.CustomDateTimeInterceptor.java

License:Apache License

public void intercept(ValidationJson in, Validation out) {
    final Integer eventDateStamp = in.getEventDateStamp();
    final Integer eventTimeStamp = in.getEventTimeStamp();
    if (null != eventDateStamp && null != eventTimeStamp) {
        final LocalDate date = LocalDate.now().plusDays(eventDateStamp);
        final LocalTime time = LocalTime.now().plusMinutes(eventTimeStamp);
        final Calendar validationDate = GregorianCalendar.getInstance();
        validationDate.setTime(date.toDate());
        validationDate.setTimeZone(TimeZone.getDefault());
        out.setValidationDate(validationDate);
    }/*from   w  w  w .  j  a  va  2s.  co m*/
}

From source file:frontEnd.userLogadoGUI.java

private void jbtnAlugarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAlugarActionPerformed
    this.setEnabled(false);
    User user = new User(jtxtfTipo.getText(), jtxtfMatricula.getText(), jtxtfNome.getText(), null);
    Livro livro = new Livro();
    alugarLivroGUI alugarLivro = new alugarLivroGUI(this);

    int row = jtbProcuraLivro.getSelectedRow();
    if (row >= 0) {
        String[] code = { jtbProcuraLivro.getValueAt(row, 0).toString(),
                jtbProcuraLivro.getValueAt(row, 1).toString(), jtbProcuraLivro.getValueAt(row, 2).toString(),
                jtbProcuraLivro.getValueAt(row, 5).toString() };

        alugarLivro.setUser(user);//w ww. j av a  2s .  c  om
        alugarLivro.setLivro(livro);

        LocalDate now = LocalDate.now(), next = now.plusDays(7);
        String currentDate = now.toString(), nextDate = next.toString();

        livro.setTitulo(code[0]);
        livro.setEditora(code[1]);
        livro.setAutor(code[2]);
        livro.setId(code[3]);
        livro.setEntrega(nextDate);
        livro.setAluguel(currentDate);

        alugarLivro.setVisible(true);
    } else {
        JOptionPane.showMessageDialog(rootPane, "Nenhum livro selecionado.", "Erro", JOptionPane.ERROR_MESSAGE);
    }
}