Example usage for java.time LocalDate plusYears

List of usage examples for java.time LocalDate plusYears

Introduction

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

Prototype

public LocalDate plusYears(long yearsToAdd) 

Source Link

Document

Returns a copy of this LocalDate with the specified number of years added.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = a.plusYears(100);
    System.out.println(b);//  ww w. j  av a2  s  .co m
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate today = LocalDate.now();

    LocalDate nextYear = today.plusYears(1);

    System.out.println(String.format("Today %s and next year %s", today, nextYear));
}

From source file:Main.java

public static void main(String[] args) {
    Period p = Period.between(LocalDate.of(2009, Month.JANUARY, 21), LocalDate.of(2019, Month.JANUARY, 21));

    System.out.println(p.get(ChronoUnit.DAYS));

    LocalDate today = LocalDate.now();
    LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

    LocalDate nextBDay = birthday.withYear(today.getYear());

    nextBDay = nextBDay.plusYears(1);

    p = Period.between(today, nextBDay);
    long p2 = ChronoUnit.DAYS.between(today, nextBDay);
    System.out.println(p.getMonths() + " months");
    System.out.println(p.getDays() + " days");
}

From source file:Main.java

public static void main(String[] args) {

    LocalDate today = LocalDate.now();
    LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

    LocalDate nextBDay = birthday.withYear(today.getYear());

    //If your birthday has occurred this year already, add 1 to the year.
    if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) {
        nextBDay = nextBDay.plusYears(1);
    }/* ww  w  .  j  a  v a 2 s . com*/

    Period p = Period.between(today, nextBDay);
    long p2 = ChronoUnit.DAYS.between(today, nextBDay);
    System.out.println("There are " + p.getMonths() + " months, and " + p.getDays()
            + " days until your next birthday. (" + p2 + " total)");
}

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

@FXML
protected void clearReports(ActionEvent event) throws Exception {
    LocalDate date = LocalDate.now();
    date = date.plusYears(10L);
    RadioButton radio = (RadioButton) toggleClear.getSelectedToggle();
    if (radio.getId().equals("radOlder")) {
        if (datePicker.getValue() != null) {
            date = datePicker.getValue();
        } else {//from  w  w w.  java 2s.  co m
            getContext().send(BasicConfig.MODULE_MESSAGE,
                    new AlertMessage(AlertMessage.Type.ALERT, bundle.getString("alertSelectDate")));
            return;
        }
    }

    // All ok, delete
    if (getController().clearReports(date)) {
        getModel().clearData();
        getModel().readReports();
        recalculateSize();
        hideClearOptions();
        addData();
        getContext().send(BasicConfig.MODULE_MESSAGE,
                new AlertMessage(AlertMessage.Type.INFO, bundle.getString("successDeleteReports")));
    } else {
        getContext().send(BasicConfig.MODULE_MESSAGE,
                new AlertMessage(AlertMessage.Type.ERROR, bundle.getString("errorDeleteReports")));
    }
}

From source file:com.romeikat.datamessie.core.base.ui.page.StatisticsPage.java

private String getToDate(final LocalDate date) {
    LocalDate toDate;/*from www  . java2 s .  c o m*/
    final StatisticsInterval statisticsInterval = statisticsIntervalSelector.getModelObject();
    switch (statisticsInterval) {
    case DAY:
        toDate = date;
        break;
    case WEEK:
        toDate = date.plusWeeks(1).minusDays(1);
        break;
    case MONTH:
        toDate = date.plusMonths(1).minusDays(1);
        break;
    case YEAR:
        toDate = date.plusYears(1).minusDays(1);
        break;
    default:
        toDate = null;
    }
    return DocumentsFilterPanel.formatLocalDate(toDate);
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testCreateReservationWithWrongValues() {

    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));
    Reservation reservation;//from w  ww . j  a  v  a  2 s  .  c  om

    reservation = setReservation(-5, 1, checkin, checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("wrong room id(negative value)");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, -1, checkin, checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("wrong guest id (negative value)");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, checkin.plusMonths(3), checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("checkin after checkout");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, checkin, checkout, reservationdate.plusYears(1));
    try {
        reservationManager.createReservation(reservation);
        fail("reservation date after checkin");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, checkin, null, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("checkout is null");
    } catch (IllegalArgumentException ex) {
        //OK
    }

    reservation = setReservation(1, 1, null, checkout, reservationdate);
    try {
        reservationManager.createReservation(reservation);
        fail("checkin is null");
    } catch (IllegalArgumentException ex) {
        //OK
    }
}

From source file:org.efaps.esjp.common.uiform.Field_Base.java

/**
 * @param _parameter    Parameter as passed from the eFaps API
 * @return Return containing Html Snipplet
 * @throws EFapsException on error//from w  ww.j  a v a2  s  .  co  m
 */
public Return getOptionList4DateTime(final Parameter _parameter) throws EFapsException {
    final List<DropDownPosition> positions = new ArrayList<>();
    final String dateFieldType = getProperty(_parameter, "DateFieldType", "YEAR");
    switch (dateFieldType) {
    case "MONTH":
        for (final Month month : Month.values()) {
            final DropDownPosition pos = getDropDownPosition(_parameter, month.getValue(),
                    month.getDisplayName(TextStyle.FULL, Context.getThreadContext().getLocale()));
            pos.setSelected(month.getValue() == new DateTime().getMonthOfYear());
            positions.add(pos);
        }
        break;
    case "YEAR":
    default:
        final String fromStr = getProperty(_parameter, "From", "-10");
        final String toStr = getProperty(_parameter, "To", "+10");
        LocalDate start;
        if (StringUtils.isNumeric(fromStr)) {
            start = LocalDate.of(Integer.parseInt(fromStr), 1, 1);
        } else {
            start = LocalDate.now().plusYears(Integer.parseInt(fromStr));
        }
        final LocalDate end;
        if (StringUtils.isNumeric(toStr)) {
            end = LocalDate.of(Integer.parseInt(toStr), 1, 1);
        } else {
            end = LocalDate.now().plusYears(Integer.parseInt(toStr));
        }
        while (start.isBefore(end)) {
            final DropDownPosition pos = getDropDownPosition(_parameter, start.getYear(), start.getYear());
            pos.setSelected(start.getYear() == new DateTime().getYear());
            positions.add(pos);
            start = start.plusYears(1);
        }
        break;
    }
    final Return ret = new Return();
    ret.put(ReturnValues.VALUES, positions);
    return ret;
}