List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:lumbermill.internal.elasticsearch.ElasticSearchOkHttpClientImpl.java
private String indexRowWithDateAndType(JsonEvent event) { Optional<String> formattedType = type.format(event); if (!formattedType.isPresent()) { throw new IllegalStateException( "Issue with type, could not extract field from event " + type.original()); }/*from w w w . ja v a 2 s .c om*/ Optional<String> formattedIndex = index.format(event); if (!formattedIndex.isPresent()) { throw new IllegalStateException( "Issue with index, could not extract field from event: " + index.original()); } Optional<String> formattedDocumentId = Optional.empty(); if (documentId.isPresent()) { formattedDocumentId = documentId.get().format(event); if (!formattedDocumentId.isPresent()) { throw new IllegalStateException( "Issue with index, could not extract field from event: " + index.original()); } } ObjectNode objectNode = OBJECT_MAPPER.createObjectNode(); ObjectNode data = OBJECT_MAPPER.createObjectNode(); // Prepare for adding day to index for each event if (indexIsPrefix) { LocalDate indexDate; // TODO: Not sure how to handle this... what should be the behaviour if the specified timestamp field // does not exist if (event.has(this.timestampField)) { indexDate = LocalDate.parse(event.valueAsString(this.timestampField).substring(0, 10), DateTimeFormatter.ISO_DATE); } else { indexDate = LocalDate.now(); } data.put("_index", formattedIndex.get() + indexDate.format(DateTimeFormatter.ofPattern("yyyy.MM.dd"))); } else { data.put("_index", formattedIndex.get()); } data.put("_type", formattedType.get()); if (formattedDocumentId.isPresent()) { data.put("_id", formattedDocumentId.get()); } objectNode.set("index", data); return objectNode.toString(); }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testUpdateDisplayName() { 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, null); Event event = eventUsername.getKey(); try {//from w w w . j a va2 s. c o m dataMigrator.migrateEventsToCurrentVersion(); EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId()); assertNotNull(eventMigration); //assertEquals(buildTimestamp, eventMigration.getBuildTimestamp().toString()); assertEquals(currentVersion, eventMigration.getCurrentVersion()); Event withDescription = eventRepository.findById(event.getId()); assertNotNull(withDescription.getDisplayName()); assertEquals(event.getShortName(), withDescription.getShortName()); assertEquals(event.getShortName(), withDescription.getDisplayName()); } finally { eventManager.deleteEvent(event.getId(), eventUsername.getValue()); } }
From source file:org.dhatim.fastexcel.Correctness.java
@Test public void multipleWorksheets() throws Exception { int numWs = 10; int numRows = 5000; int numCols = 6; byte[] data = writeWorkbook(wb -> { @SuppressWarnings("unchecked") CompletableFuture<Void>[] cfs = new CompletableFuture[numWs]; for (int i = 0; i < cfs.length; ++i) { Worksheet ws = wb.newWorksheet("Sheet " + i); CompletableFuture<Void> cf = CompletableFuture.runAsync(() -> { for (int j = 0; j < numCols; ++j) { ws.value(0, j, "Column " + j); ws.style(0, j).bold().fontSize(12).fillColor(Color.GRAY2).set(); for (int k = 1; k <= numRows; ++k) { switch (j) { case 0: ws.value(k, j, "String value " + k); break; case 1: ws.value(k, j, 2); break; case 2: ws.value(k, j, 3L); break; case 3: ws.value(k, j, 0.123); break; case 4: ws.value(k, j, new Date()); ws.style(k, j).format("yyyy-MM-dd HH:mm:ss").set(); break; case 5: ws.value(k, j, LocalDate.now()); ws.style(k, j).format("yyyy-MM-dd").set(); break; default: throw new IllegalArgumentException(); }/*from w w w . j a v a 2s . co m*/ } } ws.formula(numRows + 1, 1, "=SUM(" + ws.range(1, 1, numRows, 1).toString() + ")"); ws.formula(numRows + 1, 2, "=SUM(" + ws.range(1, 2, numRows, 2).toString() + ")"); ws.formula(numRows + 1, 3, "=SUM(" + ws.range(1, 3, numRows, 3).toString() + ")"); ws.formula(numRows + 1, 4, "=AVERAGE(" + ws.range(1, 4, numRows, 4).toString() + ")"); ws.style(numRows + 1, 4).format("yyyy-MM-dd HH:mm:ss").set(); ws.formula(numRows + 1, 5, "=AVERAGE(" + ws.range(1, 5, numRows, 5).toString() + ")"); ws.style(numRows + 1, 5).format("yyyy-MM-dd").bold().italic().fontColor(Color.RED) .fontName("Garamond").fontSize(new BigDecimal("14.5")).horizontalAlignment("center") .verticalAlignment("top").wrapText(true).set(); ws.range(1, 0, numRows, numCols - 1).style().borderColor(Color.RED).borderStyle("thick") .shadeAlternateRows(Color.RED).set(); }); cfs[i] = cf; } try { CompletableFuture.allOf(cfs).get(); } catch (InterruptedException | ExecutionException ex) { throw new RuntimeException(ex); } }); // Check generated workbook with Apache POI XSSFWorkbook xwb = new XSSFWorkbook(new ByteArrayInputStream(data)); assertThat(xwb.getActiveSheetIndex()).isEqualTo(0); assertThat(xwb.getNumberOfSheets()).isEqualTo(numWs); for (int i = 0; i < numWs; ++i) { assertThat(xwb.getSheetName(i)).isEqualTo("Sheet " + i); XSSFSheet xws = xwb.getSheetAt(i); assertThat(xws.getLastRowNum()).isEqualTo(numRows + 1); for (int j = 1; j <= numRows; ++j) { assertThat(xws.getRow(j).getCell(0).getStringCellValue()).isEqualTo("String value " + j); } } }
From source file:org.tightblog.util.Utilities.java
/** * Parse date as either 6-char or 8-char format. Use current date if date not provided * in URL (e.g., a permalink), more than 30 days in the future, or not valid *///from w ww.j a v a 2s .c o m public static LocalDate parseURLDate(String dateString) { LocalDate ret = null; try { if (StringUtils.isNumeric(dateString)) { if (dateString.length() == 8) { ret = LocalDate.parse(dateString, Utilities.YMD_FORMATTER); } else if (dateString.length() == 6) { YearMonth tmp = YearMonth.parse(dateString, Utilities.YM_FORMATTER); ret = tmp.atDay(1); } } } catch (DateTimeParseException ignored) { ret = null; } // make sure the requested date is not more than a month in the future if (ret == null || ret.isAfter(LocalDate.now().plusDays(30))) { ret = LocalDate.now(); } return ret; }
From source file:alfio.manager.AdminReservationManagerIntegrationTest.java
@Test public void testReserveMixed() 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, "", false, 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"); TicketCategory existingCategory = ticketCategoryRepository.findByEventId(event.getId()).get(0); Category resExistingCategory = new Category(existingCategory.getId(), "", existingCategory.getPrice()); Category resNewCategory = new Category(null, "name", new BigDecimal("100.00")); int attendees = 1; List<TicketsInfo> ticketsInfoList = Arrays.asList( new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, false), new TicketsInfo(resNewCategory, generateAttendees(attendees), false, false), new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, 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());// ww w .j a va 2 s . com Pair<TicketReservation, List<Ticket>> data = result.getData(); List<Ticket> tickets = data.getRight(); assertTrue(tickets.size() == 3); assertNotNull(data.getLeft()); assertTrue(tickets.stream().allMatch(t -> t.getTicketsReservationId().equals(data.getKey().getId()))); int resExistingCategoryId = tickets.get(0).getCategoryId(); int resNewCategoryId = tickets.get(2).getCategoryId(); Event modified = eventManager.getSingleEvent(event.getShortName(), username); assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue()); assertEquals(3, ticketRepository .findPendingTicketsInCategories(Arrays.asList(resExistingCategoryId, resNewCategoryId)).size()); assertEquals(3, ticketRepository.findTicketsInReservation(data.getLeft().getId()).size()); String reservationId = data.getLeft().getId(); assertEquals(ticketRepository.findTicketsInReservation(reservationId).stream().findFirst().get().getId(), ticketRepository.findFirstTicketInReservation(reservationId).get().getId()); 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.romeikat.datamessie.core.processing.task.documentProcessing.DocumentsProcessingTask.java
private LocalDate getNextDownloadedDate(final LocalDate downloadedDate) { // If download date is current date (or future), remain at current date final LocalDate now = LocalDate.now(); if (!downloadedDate.isBefore(now)) { return now; }//w w w. ja v a 2s .com // Otherwise, go to next date return downloadedDate.plusDays(1); }
From source file:com.github.drbookings.ui.controller.UpcomingController.java
private void update() { final int lookAheadDays = SettingsManager.getInstance().getUpcomingLookAhead(); this.box.getChildren().clear(); for (int i = 0; i < lookAheadDays; i++) { final LocalDate date = LocalDate.now().plusDays(i); final List<BookingEntry> upcomingBookings = manager.getBookingEntries().stream() .filter(b -> b.getDate().equals(date)).collect(Collectors.toList()); final List<CleaningEntry> upcomingCleanings = manager.getCleaningEntries().stream() .filter(c -> c.getDate().equals(date)).collect(Collectors.toList()); addEvents(date, upcomingBookings, upcomingCleanings); if (i != lookAheadDays - 1) { this.box.getChildren().add(new Separator()); }//from w w w .ja va2 s . c o m } }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testAddUnboundedCategoryShrinkBoundedCategory() { //create the event with a single category which contains all the tickets 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, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/* ww w. ja v a2s . com*/ Event event = pair.getKey(); //shrink the original category to AVAILABLE_SEATS - 2, this would free two seats int categoryId = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0).getId(); TicketCategoryModification shrink = new TicketCategoryModification(categoryId, "default", AVAILABLE_SEATS - 2, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null); eventManager.updateCategory(categoryId, event.getId(), shrink, pair.getRight()); //now insert an unbounded ticket category TicketCategoryModification tcm = 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); eventManager.insertCategory(event.getId(), tcm, pair.getValue()); waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId()); assertNotNull(tickets); assertFalse(tickets.isEmpty()); assertEquals(AVAILABLE_SEATS, tickets.size()); assertEquals(18, tickets.stream().filter(t -> t.getCategoryId() != null && t.getCategoryId() == categoryId).count()); assertEquals(2, tickets.stream().filter(t -> t.getCategoryId() == null).count()); }
From source file:ec.edu.chyc.manejopersonal.managebean.GestorPersona.java
public String agregarTitulo() { PersonaTitulo personaTituloNuevo = new PersonaTitulo(); List<Universidad> listaUniversidades = GestorGeneral.getInstance().getListaUniversidades(); List<Titulo> listaTitulos = GestorGeneral.getInstance().getListaTitulos(); if (listaUniversidades.size() > 0) { personaTituloNuevo.setUniversidad(listaUniversidades.get(0)); }//from ww w .j a v a 2 s .c o m if (listaTitulos.size() > 0) { personaTituloNuevo.setTitulo(listaTitulos.get(0)); } personaTituloNuevo.setAnio(LocalDate.now().getYear()); personaTituloNuevo.setId(idTituloPersonaGenerado); listaPersonaTitulos.add(personaTituloNuevo); //listaTitulos.add(nuevoTitulo); universidad = new Universidad(); titulo = new Titulo(); idTituloPersonaGenerado--; return ""; }
From source file:com.romeikat.datamessie.core.base.service.DocumentService.java
private LocalDate getNextDownloadedDate(final LocalDate downloadedDate) { // Increase only up to current date final LocalDate now = LocalDate.now(); if (downloadedDate.isAfter(now)) { return null; }/*from w w w. j a va 2 s . co m*/ // Otherwise, go to next date return downloadedDate.plusDays(1); }