Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

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

Prototype

public static LocalDate now() 

Source Link

Document

Obtains the current date from the system clock in the default time-zone.

Usage

From source file:dk.dma.vessel.track.model.VesselTarget.java

/**
 * Updates the max-speed for today./*from  w  w w . java  2  s  .c o  m*/
 * This should be used with care, as it involves two operations:
 * <ul>
 *     <li>Update the speed for today if it is larger that the existing value</li>
 *     <li>Reset the max-speed of tomorrow</li>
 * </ul>
 *
 * @param speed the speed to write
 */
public void updateMaxSpeedToday(short speed) {
    long day = LocalDate.now().toEpochDay();
    short oldSpeed = readMaxSpeed(day);
    if (speed > oldSpeed) {
        writeMaxSpeed(day, speed);
    }
    writeMaxSpeed(day + 1, (short) 0);
}

From source file:me.childintime.childintime.ui.window.tool.BmiToolDialog.java

/**
 * Creates a sample dataset.//from  ww w  . j ava2s .c  o  m
 *
 * @return a sample dataset.
 */
private void updateChartDataset() {
    // Clear the data set
    this.dataset.removeAllSeries();

    try {
        // Create the data series
        final XYSeries lengthSeries = new XYSeries("Length (cm)");
        final XYSeries weightSeries = new XYSeries("Weight (kg)");
        final XYSeries bmiSeries = new XYSeries("BMI");

        // Get the student
        Student student = (Student) this.studentList.getSelectedItem();

        // Make sure a student is selected
        if (student == null)
            return;

        // Get the student birthdate
        Date birthdate = (Date) student.getField(StudentFields.BIRTHDAY);

        // Age
        final long age = ChronoUnit.YEARS
                .between(birthdate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());

        // Loop through the list of body states
        for (AbstractEntity abstractEntity : Core.getInstance().getBodyStateManager().getEntities()) {
            // Cast the entity to a body state
            BodyState bodyState = (BodyState) abstractEntity;

            // Make sure the student owns this body state
            try {
                if (!bodyState.getField(BodyStateFields.STUDENT_ID).equals(student))
                    continue;

            } catch (Exception e) {
                e.printStackTrace();
            }

            // Get the measurement date
            final Date measurementDate = (Date) bodyState.getField(BodyStateFields.DATE);

            // Age
            final long measurementAge = ChronoUnit.YEARS.between(
                    measurementDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());

            // Get the length and weight
            final int length = (int) bodyState.getField(BodyStateFields.LENGTH);
            final double weight = ((int) bodyState.getField(BodyStateFields.WEIGHT)) / 1000.0;

            // Calculate the BMI
            final double bmi = weight / Math.pow((length / 100.0), 2);

            // Add the data to the sets
            lengthSeries.add(age - measurementAge, length);
            weightSeries.add(age - measurementAge, weight);
            bmiSeries.add(age - measurementAge, bmi);
        }

        // Add the data series to the set
        this.dataset.addSeries(bmiSeries);
        this.dataset.addSeries(lengthSeries);
        this.dataset.addSeries(weightSeries);

    } catch (Exception e) {
        e.printStackTrace();
    }

    // Re set the dataset
    this.chart.getXYPlot().setDataset(this.dataset);
}

From source file:com.iselect.kernal.pageflow.service.PageFlowServiceImpl.java

/**
 * the main purpose of the method is to update data to model to update into
 * DBSM the method will clone those properties from responseDto to
 * responseModel: - returnRedirect - returnPath - returnView - modifiedDate
 * - transId - userJob/*from w w w . j  av a2 s .c om*/
 *
 * @param responseDto
 * @param responseModel
 * @return
 */
private PageResponseModel toPageFlowResponseModel(PageResponseDto responseDto,
        PageResponseModel responseModel) {
    if (responseDto == null) {
        return null;
    }
    if (responseModel == null) {
        responseModel = new PageResponseModelImpl();
    }
    responseModel.setId(responseDto.getId());
    responseModel.setReturnRedirect(responseDto.getReturnRedirect());
    responseModel.setReturnPath(responseDto.getReturnPath());
    responseModel.setReturnView(responseDto.getReturnView());
    responseModel.setTransId(responseDto.getTransId());
    responseModel.setUserJob(responseDto.getUserJob());
    responseModel.setModifiedDate(java.sql.Date.valueOf(LocalDate.now()));
    return responseModel;
}

From source file:alfio.manager.AdminReservationManagerIntegrationTest.java

@Test
public void testConfirmReservation() throws Exception {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Triple<Event, String, TicketReservation> testResult = performExistingCategoryTest(categories, true,
            Collections.singletonList(2), false, true, 0, AVAILABLE_SEATS);
    assertNotNull(testResult);/*www. j  a  va 2s  .c o m*/
    Result<Triple<TicketReservation, List<Ticket>, Event>> result = adminReservationManager.confirmReservation(
            testResult.getLeft().getShortName(), testResult.getRight().getId(), testResult.getMiddle());
    assertTrue(result.isSuccess());
    Triple<TicketReservation, List<Ticket>, Event> triple = result.getData();
    assertEquals(TicketReservation.TicketReservationStatus.COMPLETE, triple.getLeft().getStatus());
    triple.getMiddle().forEach(t -> assertEquals(Ticket.TicketStatus.ACQUIRED, t.getStatus()));
    assertTrue(emailMessageRepository.findByEventId(triple.getRight().getId(), 0, 50, null).isEmpty());
    ticketCategoryRepository.findByEventId(triple.getRight().getId())
            .forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream()
                    .allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
    assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(triple.getRight().getId())
            .contains(triple.getLeft().getId()));
}

From source file:com.realdolmen.rdfleet.service.EmployeeService.java

private boolean checkIfEmployeeCanOrderCar(String email) {
    RdEmployee rdEmployee = findRdEmployeeByEmail(email);
    LocalDate fourYearsAgo = LocalDate.now().minusYears(4);
    if (rdEmployee.getCurrentOrder() == null)
        return true;
    if (rdEmployee.getCurrentOrder().getDateReceived() == null)
        if (rdEmployee.getCurrentOrder().getOrderedCar().getCarStatus() == CarStatus.PENDING)
            return false;

    if (rdEmployee.getCurrentOrder().getDateReceived() != null
            && rdEmployee.getCurrentOrder().getDateReceived().isBefore(fourYearsAgo))
        return true;
    if (rdEmployee.getCurrentOrder().getOrderedCar() == null)
        return true;
    if (rdEmployee.getCurrentOrder().getOrderedCar().getMileage() > 160000)
        return true;
    return false;
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testIncreaseEventSeatsWithABoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);//www .j  av a  2  s  . c om
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(20, tickets.size());
    assertEquals(20, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() != null).count());
}

From source file:alfio.manager.TicketReservationManagerIntegrationTest.java

@Test(expected = TicketReservationManager.NotEnoughTicketsException.class)
public void testTicketSelectionNotEnoughTicketsAvailable() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/*from  ww w .ja va 2  s  . c  o m*/

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).stream()
            .filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS + 1);
    tr.setTicketCategoryId(unbounded.getId());
    TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());

    ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod),
            Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(),
            Locale.ENGLISH, false);
}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testFixCategoriesSize() {
    List<TicketCategoryModification> categories = Arrays.asList(
            new TicketCategoryModification(null, "default", AVAILABLE_SEATS - 1,
                    new DateTimeModification(LocalDate.now(), LocalTime.now()),
                    new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN,
                    false, "", true, null, null, null, null, null),
            new TicketCategoryModification(null, "default", 1,
                    new DateTimeModification(LocalDate.now(), LocalTime.now()),
                    new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN,
                    false, "", false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();
    TicketCategory firstCategory = ticketCategoryRepository.findByEventId(event.getId()).stream()
            .filter(TicketCategory::isBounded).findFirst().orElseThrow(IllegalStateException::new);
    int firstCategoryID = firstCategory.getId();
    ticketCategoryRepository.updateSeatsAvailability(firstCategoryID, AVAILABLE_SEATS + 1);
    dataMigrator.fixCategoriesSize(event);
    assertEquals(AVAILABLE_SEATS - 1, ticketRepository.countAllocatedTicketsForEvent(event.getId()).intValue());
    assertEquals(1, ticketRepository.countFreeTicketsForUnbounded(event.getId()).intValue());
    assertEquals(AVAILABLE_SEATS - 1,//from  ww w. j  a  v a 2s. c  om
            ticketRepository.countFreeTickets(event.getId(), firstCategoryID).intValue());
    assertEquals(AVAILABLE_SEATS - 1, firstCategory.getMaxTickets());
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testDecreaseEventSeatsWithAnUnboundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);/*from  www .  j a va 2 s  .  com*/
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(10, tickets.size());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}

From source file:alfio.manager.TicketReservationManagerIntegrationTest.java

@Test
public void testDeletePendingPaymentUnboundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository)
            .getKey();/*from   www .  j a  v  a 2  s.c  om*/

    TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).get(0);

    TicketReservationModification tr = new TicketReservationModification();
    tr.setAmount(AVAILABLE_SEATS / 2 + 1);
    tr.setTicketCategoryId(unbounded.getId());

    TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr,
            Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event,
            Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1),
            Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch",
            new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", reservationCost,
            Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
    assertTrue(result.isSuccessful());
    ticketReservationManager.deleteOfflinePayment(event, reservationId, false);
    waitingQueueManager.distributeSeats(event);

    mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod),
            Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(),
            Locale.ENGLISH, false);
    reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch",
            new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "", reservationCost,
            Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
    assertTrue(result.isSuccessful());
}