Example usage for java.time LocalDate plusMonths

List of usage examples for java.time LocalDate plusMonths

Introduction

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

Prototype

public LocalDate plusMonths(long monthsToAdd) 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    // Create an adjuster that retruns a date after 3 months and 2 days
    TemporalAdjuster adjuster = TemporalAdjusters
            .ofDateAdjuster((LocalDate date) -> date.plusMonths(3).plusDays(2));

    LocalDate today = LocalDate.now();
    LocalDate dayAfter3Mon2Day = today.with(adjuster);
    System.out.println("Today: " + today);
    System.out.println("After 3  months  and  2  days: " + dayAfter3Mon2Day);

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = a.plusMonths(100);
    System.out.println(b);//from w  ww  .j  av a2s.  c om
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    LocalDate localDate1 = localDate.plusDays(5);
    System.out.println(localDate1);
    LocalDate localDate2 = localDate.plusMonths(3);
    System.out.println(localDate2);
    LocalDate localDate3 = localDate.plusWeeks(3);
    System.out.println(localDate3);
}

From source file:Main.java

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

    // plus and minus operations
    System.out.println("10 days after today will be " + today.plusDays(10));
    System.out.println("3 weeks after today will be " + today.plusWeeks(3));
    System.out.println("20 months after today will be " + today.plusMonths(20));

    System.out.println("10 days before today will be " + today.minusDays(10));
    System.out.println("3 weeks before today will be " + today.minusWeeks(3));
    System.out.println("20 months before today will be " + today.minusMonths(20));

}

From source file:Main.java

@Override
public Temporal adjustInto(Temporal input) {
    LocalDate date = LocalDate.from(input);
    LocalDate nextMonth = date.plusMonths(1);
    LocalDate firstTuesdayInNextMonth = nextMonth.with(TemporalAdjusters.firstInMonth(DayOfWeek.TUESDAY));
    return input.with(firstTuesdayInNextMonth);
}

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

private String getToDate(final LocalDate date) {
    LocalDate toDate;//from   w  w w.j  a  va 2 s .  c om
    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:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

private void handleMonthlyInOutChartMouseClickEvent(Account account, LocalDate month, MouseEvent event) {
    if (event.getClickCount() == 2) {
        TransactionFilter filter = new TransactionFilter(account, null, null,
                new ValueRange<>(month.withDayOfMonth(1), month.plusMonths(1).withDayOfMonth(1).minusDays(1)),
                new ValueRange<>(null, null), new ValueRange<>(null, null));
        chartFrame.getScene().lookup("#tabPane").fireEvent(new ShowTransactionsEvent(filter));
    }/*  w  w w. j  a  v a  2 s  .co  m*/
}

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  va 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:ui.Analyze.java

private Component buatPermintaan(LocalDate l) throws SQLException {
    org.jfree.data.general.DefaultPieDataset data = new org.jfree.data.general.DefaultPieDataset();
    java.sql.PreparedStatement p = d.getPS(
            "select detjual.brg,sum(detjual.jum)as qty from jual inner join detjual where jual.tgl>=? and "
                    + "jual.tgl<? group by detjual.brg");
    p.setDate(1, Date.valueOf(l));
    p.setDate(2, Date.valueOf(l.plusMonths(1)));
    java.sql.ResultSet r = p.executeQuery();
    while (r.next())
        data.setValue(getNamaBrg(r.getString("brg")), r.getDouble("qty"));
    r.close();//from   w  w  w. j av  a  2  s .c  o  m
    p.close();
    return new org.jfree.chart.ChartPanel(ChartFactory.createPieChart("PERMINTAAN", data, true, true, false));
}

From source file:ch.algotrader.service.LookupServiceTest.java

@Test
public void testGetSubscribedFutures() {

    SecurityFamily family1 = new SecurityFamilyImpl();
    family1.setName("Forex1");
    family1.setTickSizePattern("0<0.1");
    family1.setCurrency(Currency.USD);

    Strategy strategy1 = new StrategyImpl();
    strategy1.setName("Strategy1");

    LocalDate today = LocalDate.now();

    Future future1 = new FutureImpl();
    future1.setSecurityFamily(family1);/*www .j  av  a  2 s.  com*/
    future1.setExpiration(DateTimeLegacy.toLocalDate(today));
    future1.setMonthYear(DateTimePatterns.MONTH_YEAR.format(today));

    LocalDate nextMonth = today.plusMonths(1);

    Future future2 = new FutureImpl();
    future2.setSecurityFamily(family1);
    future2.setExpiration(DateTimeLegacy.toLocalDate(nextMonth));
    future2.setMonthYear(DateTimePatterns.MONTH_YEAR.format(nextMonth));

    this.session.save(family1);
    this.session.save(future1);
    this.session.save(future2);
    this.session.flush();

    List<Future> futures1 = lookupService.getSubscribedFutures();

    Assert.assertEquals(0, futures1.size());

    Subscription subscription1 = new SubscriptionImpl();
    subscription1.setFeedType(FeedType.SIM.name());
    subscription1.setSecurity(future1);
    subscription1.setStrategy(strategy1);

    this.session.save(strategy1);
    this.session.save(subscription1);

    this.session.flush();

    List<Future> futures2 = lookupService.getSubscribedFutures();

    Assert.assertEquals(1, futures2.size());

    Assert.assertSame(future1, futures2.get(0));
    Assert.assertSame(family1, futures2.get(0).getSecurityFamily());

    Subscription subscription2 = new SubscriptionImpl();
    subscription2.setFeedType(FeedType.BB.name());
    subscription2.setSecurity(future2);
    subscription2.setStrategy(strategy1);

    this.session.save(subscription2);

    this.session.flush();

    List<Future> futures3 = lookupService.getSubscribedFutures();

    Assert.assertEquals(2, futures3.size());

    Assert.assertSame(future1, futures3.get(0));
    Assert.assertSame(family1, futures3.get(0).getSecurityFamily());
    Assert.assertSame(future2, futures3.get(1));
    Assert.assertSame(family1, futures3.get(1).getSecurityFamily());
}