Example usage for java.time LocalDate plusDays

List of usage examples for java.time LocalDate plusDays

Introduction

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

Prototype

public LocalDate plusDays(long daysToAdd) 

Source Link

Document

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

Usage

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

private LocalDate parseLocalDate(final StringValue stringValue) {
    final LocalDate today = LocalDate.now();
    // No date corresponds to today
    if (stringValue == null) {
        return today;
    }//  w  ww  . jav a 2s.com
    // 0 corresponds to no date
    if (stringValue.toString().equals("0")) {
        return null;
    }
    // Negative numbers correspond to number of days from today in the past
    try {
        final int numberOfDays = Integer.parseInt(stringValue.toString());
        if (numberOfDays < 0) {
            final LocalDate localDate = today.plusDays(numberOfDays);
            return localDate;
        }
    } catch (final NumberFormatException e) {
    }
    // Date pattern
    final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
    try {
        final LocalDate localDate = LocalDate.parse(stringValue.toString(), dateFormatter);
        return localDate;
    } catch (final IllegalArgumentException ex) {
    }
    // Ohterwise, use today
    return today;
}

From source file:net.resheim.eclipse.timekeeper.ui.Activator.java

/**
 * Returns a list of weekday names and dates, using the default locale to
 * determine the first day of the week (Sunday or Monday).
 *
 * @param date//from  www . j  av a 2 s .  co m
 *            starting date
 * @return an array with weekday names and dates
 */
public String[] getHeadings(LocalDate date) {
    String[] headings = new String[7];
    WeekFields weekFields = WeekFields.of(Locale.getDefault());
    // Current day in the week
    int day = date.get(weekFields.dayOfWeek());
    // First date of the week
    LocalDate first = date.minusDays(day - 1);
    for (int i = 0; i < 7; i++) {
        headings[i] = formatter.format(first);
        first = first.plusDays(1);
    }
    return headings;
}

From source file:co.com.soinsoftware.hotelero.view.JFRoomPayment.java

private Date getFinalDate(final Date initialDate, final int hour) {
    final LocalDate today = LocalDate.now();
    LocalDateTime finalDateTime = null;
    if (DateUtils.isSameDay(initialDate, new Date())) {
        finalDateTime = today.plusDays(1).atTime(LocalTime.of(hour, 0));
    } else {// ww w.  j ava  2s .co  m
        finalDateTime = today.atTime(LocalTime.of(hour, 0));
    }
    final ZonedDateTime zdt = finalDateTime.atZone(ZoneId.systemDefault());
    return Date.from(zdt.toInstant());
}

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

@Test
public void TestdeleteRoom() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation r1 = setReservation(1, 1, checkin, checkout, reservationdate);
    Reservation r2 = setReservation(2, 2, checkin.plusDays(1), checkout, reservationdate.plusDays(2));
    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    assertNotNull(reservationManager.findReservation(r1.getReservationId()));
    assertNotNull(reservationManager.findReservation(r2.getReservationId()));

    reservationManager.deleteReservation(r1);

    assertNull(reservationManager.findReservation(r1.getReservationId()));
    assertNotNull(reservationManager.findReservation(r2.getReservationId()));
}

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

@Test
public void testUpdateReservation() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation reservation1 = setReservation(1L, 1L, checkin, checkout, reservationdate);
    Reservation reservation2 = setReservation(2L, 2L, checkin.plusDays(1), checkout,
            reservationdate.plusDays(2));

    reservationManager.createReservation(reservation1);
    reservationManager.createReservation(reservation2);

    Long reservationId = reservation1.getReservationId();

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setRoomId(3L);/*from w w w  .  jav  a  2  s.  c o  m*/
    reservationManager.updateReservation(reservation1);
    assertThat("room id was not changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(1L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(), is(equalTo(reservationdate)));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setGuestId(3L);
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was not changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(), is(equalTo(reservationdate)));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setReservationDate(reservationdate.plusDays(1));
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was not changed", reservation1.getReservationDate(),
            is(equalTo(reservationdate.plusDays(1))));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin)));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setCheckinDate(checkin.plusDays(2));
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(),
            is(equalTo(reservationdate.plusDays(1))));
    assertThat("checkin date was not changed", reservation1.getCheckinDate(), is(equalTo(checkin.plusDays(2))));
    assertThat("checkout date was changed", reservation1.getCheckoutDate(), is(equalTo(checkout)));

    reservation1 = reservationManager.findReservation(reservationId);
    reservation1.setCheckoutDate(checkout.plusDays(2));
    reservationManager.updateReservation(reservation1);
    assertThat("room id was changed", reservation1.getRoomId(), is(equalTo(3L)));
    assertThat("guest id was changed", reservation1.getGuestId(), is(equalTo(3L)));
    assertThat("resrvation date was changed", reservation1.getReservationDate(),
            is(equalTo(reservationdate.plusDays(1))));
    assertThat("checkin date was changed", reservation1.getCheckinDate(), is(equalTo(checkin.plusDays(2))));
    assertThat("checkout date was not changed", reservation1.getCheckoutDate(),
            is(equalTo(checkout.plusDays(2))));

    assertDeepEquals(reservation2, reservationManager.findReservation(reservation2.getReservationId()));
}

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

@Test
public void testGetAllReservations() {

    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    assertTrue(reservationManager.findAllReservations().isEmpty());

    Reservation r1 = setReservation(1, 1, checkin, checkout, reservationdate);
    Reservation r2 = setReservation(2, 2, checkin.plusDays(1), checkout, reservationdate.plusDays(2));

    reservationManager.createReservation(r1);
    reservationManager.createReservation(r2);

    List<Reservation> expected = Arrays.asList(r1, r2);
    List<Reservation> actual = reservationManager.findAllReservations();

    Collections.sort(actual, idComparator);
    Collections.sort(expected, idComparator);

    assertEquals("saved and retrieved reservations differ", expected, actual);
    assertDeepEquals(expected, actual);// w ww  . ja va 2 s . c  o m
}

From source file:org.gradoop.flink.datagen.transactions.foodbroker.config.FoodBrokerConfig.java

/**
 * Calculates and returns the new date corresponding to the quality of the
 * influencing master data objects.//from www. j  a  va  2s .  co m
 *
 * @param date initial date
 * @param influencingMasterDataQuality list of influencing master data quality
 * @param node the transactional data node
 * @param key the key to load from
 * @return long representation of the new date
 */
public LocalDate delayDelayConfiguration(LocalDate date, List<Float> influencingMasterDataQuality, String node,
        String key) {
    // get the delay from range
    int delay = getIntRangeConfigurationValue(influencingMasterDataQuality, node, key, false);
    return date.plusDays(delay);
}

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

private LocalDate getFromDate() {
    final LocalDate toDate = getToDate();
    if (toDate == null) {
        return LocalDate.now();
    }/*from   w  ww.j  a v  a 2s. c  o m*/

    Integer statisticsPeriod = DataMessieSession.get().getStatisticsPeriodModel().getObject();
    if (statisticsPeriod == null) {
        return LocalDate.now();
    }

    final StatisticsInterval statisticsInterval = DataMessieSession.get().getStatisticsIntervalModel()
            .getObject();
    if (statisticsInterval == null) {
        return LocalDate.now();
    }

    // Minimum value is 1
    statisticsPeriod = Math.max(statisticsPeriod, 1);

    // Calculate
    final LocalDate fromDate = toDate.plusDays(1);
    switch (statisticsInterval) {
    case DAY:
        return fromDate.minusDays(statisticsPeriod);
    case WEEK:
        return fromDate.minusWeeks(statisticsPeriod);
    case MONTH:
        return fromDate.minusMonths(statisticsPeriod);
    case YEAR:
        return fromDate.minusYears(statisticsPeriod);
    default:
        return LocalDate.now();
    }
}

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;/*from  w w w  .  j a va2  s  . c om*/
    LocalDate endDate = null;

    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"));
}

From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java

@Test
public void getMessageListShouldReturnSkipMessagesWhenPositionIsGiven() throws Exception {
    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");

    LocalDate date = LocalDate.now();
    mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
            convertToDate(date.plusDays(1)), false, new Flags());
    ComposedMessageId message2 = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), convertToDate(date), false,
            new Flags());
    await();// w  w  w  . j  a v a 2  s  . c o  m

    given().header("Authorization", accessToken.serialize())
            .body("[[\"getMessageList\", {\"position\":1, \"sort\":[\"date desc\"]}, \"#0\"]]").when()
            .post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList"))
            .body(ARGUMENTS + ".messageIds", contains(message2.getMessageId().serialize()));
}