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:se.inera.intyg.intygstjanst.persistence.model.dao.impl.SjukfallCertificateDaoImplTest.java

private List<SjukfallCertificateWorkCapacity> nonOngoingWorkCapacities() {
    List<SjukfallCertificateWorkCapacity> workCapacities = new ArrayList<>();
    SjukfallCertificateWorkCapacity wc = new SjukfallCertificateWorkCapacity();
    wc.setCapacityPercentage(100);//from  w ww .  j  ava  2s . c  o m
    wc.setFromDate(LocalDate.now().minusWeeks(2).format(DateTimeFormatter.ISO_DATE));
    wc.setToDate(LocalDate.now().minusWeeks(1).format(DateTimeFormatter.ISO_DATE));
    workCapacities.add(wc);
    return workCapacities;
}

From source file:org.silverpeas.core.calendar.CalendarSynchronizationIT.java

@Test
public void synchronizeASecondTimeFromANonEmptyCalendarShouldDoesNothing() throws Exception {
    Calendar calendar = prepareSynchronizedCalendar();
    OffsetDateTime lastSynchronizationDate = calendar.getLastSynchronizationDate().get();

    ICalendarImportResult result = calendar.synchronize();
    assertThat(result.isEmpty(), is(true));

    Calendar synchronizedCalendar = Calendar.getById(CALENDAR_ID);
    assertThat(synchronizedCalendar.getLastSynchronizationDate().get(), greaterThan(lastSynchronizationDate));
    assertThat(synchronizedCalendar.isEmpty(), is(false));

    List<CalendarEvent> events = Calendar.getEvents().filter(f -> f.onCalendar(synchronizedCalendar)).stream()
            .collect(Collectors.toList());
    assertThat(events.size(), is(2));//from   w ww  . ja va 2s. c o  m
    events.forEach(e -> {
        assertThat(e.getLastSynchronizationDate().toLocalDate(), is(LocalDate.now()));
    });
}

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

@Test
public void testMigrationWithExistingRecord() {
    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));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();

    try {/* ww w  .  j a  v a2 s .  co  m*/
        eventMigrationRepository.insertMigrationData(event.getId(), "1.4",
                ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1), EventMigration.Status.COMPLETE.toString());
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(),
                PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        //assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());

        List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
        assertNotNull(tickets);
        assertFalse(tickets.isEmpty());
        assertEquals(20, tickets.size());
        assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:com.yqboots.dict.core.DataDictManagerImpl.java

/**
 * {@inheritDoc}/*from  ww w . ja  v a2s .  co  m*/
 */
@Override
public Path exports() throws IOException {
    final String fileName = properties.getExportFileNamePrefix() + LocalDate.now() + FileType.DOT_XML;

    final Path exportFileLocation = properties.getExportFileLocation();
    if (!Files.exists(exportFileLocation)) {
        Files.createDirectories(exportFileLocation);
    }

    final Path result = Paths.get(exportFileLocation + File.separator + fileName);
    try (final FileWriter writer = new FileWriter(result.toFile())) {
        final List<DataDict> dataDicts = dataDictRepository.findAll();
        jaxb2Marshaller.marshal(new DataDicts(dataDicts), new StreamResult(writer));
    }

    return result;
}

From source file:org.sonatype.nexus.repository.maven.internal.PurgeUnusedSnapshotsFacetImpl.java

/**
 * Purges snapshots from the given repository, returning a set of the affected groups for metadata rebuilding.
 *//*ww  w.  j  a  v  a 2  s .c  om*/
private Set<String> purgeSnapshotsFromRepository(final int numberOfDays) {
    LocalDate olderThan = LocalDate.now().minusDays(numberOfDays);
    UnitOfWork.beginBatch(facet(StorageFacet.class).txSupplier());
    try {
        return deleteUnusedSnapshotComponents(olderThan);
    } finally {
        UnitOfWork.end();
    }
}

From source file:alfio.manager.AdminReservationManagerIntegrationTest.java

@Test
public void testReserveFromExistingCategoryNotEnoughSeatsNoExtensionAllowedNotBounded() throws Exception {
    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));
    performExistingCategoryTest(categories, true, Collections.singletonList(AVAILABLE_SEATS + 1), false, false,
            0, AVAILABLE_SEATS);/*from w  w  w  .j  ava  2  s  . c  o  m*/
}

From source file:com.romeikat.datamessie.core.processing.task.documentProcessing.DocumentsProcessingTask.java

private LocalDate getMinDownloadedDate(final StatelessSession statelessSession) {
    if (StringUtils.isNotBlank(minDownloadedDate)) {
        Date parseDate;//from   w ww. j  a  v  a 2s .c o  m
        try {
            parseDate = DateUtils.parseDate(minDownloadedDate, "yyyy-MM-dd");
            return DateUtil.toLocalDate(parseDate);
        } catch (final ParseException e) {
            final String msg = String.format("Cound not parse minDownloadedDate %s", minDownloadedDate);
            LOG.error(msg, e);
            return null;
        }
    }

    final LocalDateTime minDownloadedDateTime = documentDao.getMinDownloaded(statelessSession);
    if (minDownloadedDateTime == null) {
        return LocalDate.now();
    }

    final LocalDate minDownloadedDate = minDownloadedDateTime.toLocalDate();
    return minDownloadedDate;
}

From source file:alfio.manager.AdminReservationManagerIntegrationTest.java

@Test
public void testReserveFromNewCategory() 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));
    Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager,
            eventManager, eventRepository);
    Event event = eventWithUsername.getKey();
    String username = eventWithUsername.getValue();
    DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
    CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch",
            "Billing Address", "en");
    Category category = new Category(null, "name", new BigDecimal("100.00"));
    int attendees = AVAILABLE_SEATS;
    List<TicketsInfo> ticketsInfoList = Collections
            .singletonList(new TicketsInfo(category, generateAttendees(attendees), true, false));
    AdminReservationModification modification = new AdminReservationModification(expiration, customerData,
            ticketsInfoList, "en", false, null);
    Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager
            .createReservation(modification, event.getShortName(), username);
    assertTrue(result.isSuccess());/*w w w . j  a  v  a 2 s .  c  o  m*/
    Pair<TicketReservation, List<Ticket>> data = result.getData();
    List<Ticket> tickets = data.getRight();
    assertTrue(tickets.size() == attendees);
    assertNotNull(data.getLeft());
    int categoryId = tickets.get(0).getCategoryId();
    Event modified = eventManager.getSingleEvent(event.getShortName(), username);
    assertEquals(attendees + 1, eventRepository.countExistingTickets(event.getId()).intValue());
    assertEquals(attendees,
            ticketRepository.findPendingTicketsInCategories(Collections.singletonList(categoryId)).size());
    TicketCategory categoryModified = ticketCategoryRepository.getByIdAndActive(categoryId, event.getId());
    assertEquals(categoryModified.getMaxTickets(), attendees);
    ticketCategoryRepository.findByEventId(event.getId())
            .forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream()
                    .allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
    adminReservationManager.confirmReservation(event.getShortName(), data.getLeft().getId(), username);
    ticketCategoryRepository.findByEventId(event.getId())
            .forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream()
                    .allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
    assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId())
            .contains(data.getLeft().getId()));
}

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

/**
 * After ordering a car it is set to pending, the fleet employee has to set the car to IN_USE.
 * This will define the car as being used, it will also add the car to the history of the user.
 * The received-date will be set on the day this method is called.
 *
 * @param rdEmployee the employee whos car should be set to in-use
 */// w  w  w. j a  v  a 2  s.c  o m
public void setEmployeeCarInUse(RdEmployee rdEmployee, String givenLicensePlate) {
    if (rdEmployee == null || rdEmployee.getId() == null)
        throw new IllegalArgumentException("The employee was not found.");

    Order currentOrder = rdEmployee.getCurrentOrder();

    if (currentOrder == null)
        throw new IllegalArgumentException("The order cannot be null.");

    EmployeeCar employeeCar = currentOrder.getOrderedCar();

    if (employeeCar == null)
        throw new IllegalArgumentException("The car to change status of cannot be null.");

    if (employeeCar.getCarStatus() != CarStatus.PENDING)
        throw new IllegalArgumentException("The car is not in PENDING state.");

    String upperCaseLicensePlate = givenLicensePlate.toUpperCase();
    if (!upperCaseLicensePlate.matches("^\\d-[A-Z]{3}-\\d{3}$"))
        throw new IllegalArgumentException(
                "The license plate is not valid. It must have the following pattern: 0-XXX-000");

    EmployeeCar byLicensePlateIgnoreCase = employeeCarRepository
            .findByLicensePlateIgnoreCase(upperCaseLicensePlate);
    if (byLicensePlateIgnoreCase != null)
        throw new IllegalArgumentException(
                "This license plate already exists in the system. Please provide a new one.");

    rdEmployee.getOrderHistory().add(rdEmployee.getCurrentOrder());
    rdEmployee.getCurrentOrder().setDateReceived(LocalDate.now());
    employeeCar.setCarStatus(CarStatus.IN_USE);
    employeeCar.setLicensePlate(upperCaseLicensePlate);

    rdEmployeeRepository.save(rdEmployee);
}

From source file:com.romeikat.datamessie.core.base.ui.panel.DocumentsFilterPanel.java

public static String formatLocalDate(final LocalDate localDate) {
    // No date corresponds to 0
    if (localDate == null) {
        return "0";
    }/* ww w. jav  a  2s .  c  o m*/
    // Today corresponds to no date
    final LocalDate today = LocalDate.now();
    if (localDate.equals(today)) {
        return null;
    }
    // Date pattern
    return localDate.format(DateTimeFormatter.ofPattern(DATE_TIME_PATTERN));
}