List of usage examples for java.time ZonedDateTime now
public static ZonedDateTime now()
From source file:org.openhab.binding.amazonechocontrol.internal.handler.AccountHandler.java
private void refreshNotifications(@Nullable JsonCommandPayloadPushNotificationChange pushPayload) { Connection currentConnection = this.connection; if (currentConnection == null) { return;// w ww.j a v a 2 s .co m } if (!currentConnection.getIsLoggedIn()) { return; } JsonNotificationResponse[] notifications; ZonedDateTime timeStamp = ZonedDateTime.now(); try { notifications = currentConnection.notifications(); } catch (IOException | URISyntaxException e) { logger.debug("refreshNotifications failed {}", e); return; } ZonedDateTime timeStampNow = ZonedDateTime.now(); for (EchoHandler child : echoHandlers) { child.updateNotifications(timeStamp, timeStampNow, pushPayload, notifications); } }
From source file:org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest.java
protected static String getTestTimeZone() { final ZonedDateTime currentTime = ZonedDateTime.now(); return currentTime.getOffset().getId().replace("Z", "+00:00"); }
From source file:alfio.manager.AdminReservationManagerIntegrationTest.java
private Triple<Event, String, TicketReservation> performExistingCategoryTest( List<TicketCategoryModification> categories, boolean bounded, List<Integer> attendeesNr, boolean addSeatsIfNotAvailable, boolean expectSuccess, int reservedTickets, int expectedEventSeats) { assertEquals("Test error: categories' size must be equal to attendees' size", categories.size(), attendeesNr.size());// w w w . j av a2s . co m 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"); Iterator<Integer> attendeesIterator = attendeesNr.iterator(); List<TicketCategory> existingCategories = ticketCategoryRepository.findByEventId(event.getId()); List<Attendee> allAttendees = new ArrayList<>(); List<TicketsInfo> ticketsInfoList = existingCategories.stream().map(existingCategory -> { Category category = new Category(existingCategory.getId(), existingCategory.getName(), existingCategory.getPrice()); List<Attendee> attendees = generateAttendees(attendeesIterator.next()); allAttendees.addAll(attendees); return new TicketsInfo(category, attendees, addSeatsIfNotAvailable, false); }).collect(toList()); AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null); if (reservedTickets > 0) { TicketReservationModification trm = new TicketReservationModification(); trm.setAmount(reservedTickets); trm.setTicketCategoryId(existingCategories.get(0).getId()); TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty()); ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false); } Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager .createReservation(modification, event.getShortName(), username); if (expectSuccess) { validateSuccess(bounded, attendeesNr, event, username, existingCategories, result, allAttendees, expectedEventSeats, reservedTickets); } else { assertFalse(result.isSuccess()); return null; } return Triple.of(eventWithUsername.getLeft(), eventWithUsername.getRight(), result.getData().getKey()); }
From source file:com.sumzerotrading.broker.ib.InteractiveBrokersBroker.java
protected ZonedDateTime getZoneDateTime() { return ZonedDateTime.now(); }
From source file:net.jmhertlein.alphonseirc.AlphonseBot.java
private void handleDadCommand(final String target, String sender, String[] args) { if (args.length == 1) { sendMessage(target, "Usage: !dad [left|list|say]"); return;// ww w .ja va 2 s. c o m } switch (args[1]) { case "left": ZonedDateTime now = ZonedDateTime.now(); this.dadLeaveTimes.put(LocalDate.now(), LocalTime.now()); sendMessage(target, "Marked dad's leave time as now (" + now.format(DateTimeFormatter.ISO_LOCAL_TIME) + ")."); break; case "list": int num = 3; if (args.length == 3) { try { num = Integer.parseInt(args[2]); if (num > 10) num = 10; } catch (NumberFormatException nfe) { sendMessage(target, "Error parsing " + args[2] + " into int: " + nfe.getMessage()); sendMessage(target, "Usage: !dad list (optional: number, default 3, max 10)"); return; } } final int prevDays = num; dadLeaveTimes.keySet().stream().sorted() .filter(date -> date.isAfter(LocalDate.now().minusDays(prevDays))) .map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " || " + dadLeaveTimes.get(date).format(DateTimeFormatter.ISO_LOCAL_TIME)) .forEach(leaveTime -> sendMessage(target, leaveTime)); break; case "say": String msg; switch (gen.nextInt(9)) { case 0: msg = "TYPES LOUDLY"; break; case 1: msg = "BREATHES DEEPLY"; break; case 2: msg = "ANGRILY TYPES AN EMAIL"; break; case 3: msg = "BACKSPACES WITH AUTHORITY"; break; case 4: msg = "STRETCHES WHILE EXHALING"; break; case 5: msg = "thinks about Happy Hour"; break; case 6: msg = "browses Yahoo! news"; break; case 7: msg = "tells everyone to GET BACK TO WORK"; break; case 8: msg = "ignores Lantzer standing in front of his desk"; break; default: msg = "Someone made nextInt() go too high"; break; } this.sendAction(target, msg); break; default: System.out.println("Bad switch on " + args[1]); } }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenOneAttachedMessageIsNotInAttachments() throws Exception { Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")).headers(ImmutableMap.of("key", "value")) .subject("subject").size(1).date(ZonedDateTime.now()).preview("preview") .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder().headers(ImmutableMap.of("key", "value")).subject("subject") .date(ZonedDateTime.now()).build())) .build();// w w w . j a v a2s . com }
From source file:org.apache.james.jmap.model.MailboxMessageTest.java
@Test public void buildShouldNotThrowWhenOneAttachedMessageIsInAttachments() throws Exception { Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")).headers(ImmutableMap.of("key", "value")) .subject("subject").size(1).date(ZonedDateTime.now()).preview("preview") .attachments(ImmutableList//from ww w .j ava 2 s . co m .of(Attachment.builder().blobId(BlobId.of("key")).size(1).type("type").build())) .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder().headers(ImmutableMap.of("key", "value")).subject("subject") .date(ZonedDateTime.now()).build())) .build(); }
From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java
@Test public void testAssignTicketToWaitingQueueBoundedCategory() { LocalDateTime start = LocalDateTime.now().minusMinutes(2); LocalDateTime end = LocalDateTime.now().plusMinutes(20); List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()), new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null)); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true"); Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository) .getKey();/*from w ww .ja v a 2s.c o m*/ TicketCategory bounded = ticketCategoryRepository.findByEventId(event.getId()).get(0); TicketReservationModification tr = new TicketReservationModification(); tr.setAmount(AVAILABLE_SEATS - 1); tr.setTicketCategoryId(bounded.getId()); TicketReservationModification tr2 = new TicketReservationModification(); tr2.setAmount(1); tr2.setTicketCategoryId(bounded.getId()); TicketReservationWithOptionalCodeModification multi = new TicketReservationWithOptionalCodeModification(tr, Optional.empty()); TicketReservationWithOptionalCodeModification single = new TicketReservationWithOptionalCodeModification( tr2, Optional.empty()); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(multi), 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()); String reservationIdSingle = ticketReservationManager.createTicketReservation(event, Collections.singletonList(single), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false); TotalPrice reservationCostSingle = ticketReservationManager .totalReservationCostWithVAT(reservationIdSingle); PaymentResult resultSingle = ticketReservationManager.confirm("", null, event, reservationIdSingle, "test@test.ch", new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "", reservationCostSingle, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null); assertTrue(resultSingle.isSuccessful()); assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation()); assertTrue( waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH)); ticketReservationManager.deleteOfflinePayment(event, reservationIdSingle, false); List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager .distributeSeats(event).collect(Collectors.toList()); assertEquals(1, subscriptions.size()); Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions .get(0); assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress()); TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle(); assertEquals(Integer.valueOf(bounded.getId()), reservation.getTicketCategoryId()); assertEquals(Integer.valueOf(1), reservation.getAmount()); assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now())); }
From source file:DataStorageTests.java
@Test public void dateTest() { storage = new Storage("{'lower':{}}"); ZonedDateTime now = ZonedDateTime.now(); Date dNow = new Date(); String dNowString = dNow.toString(); String dateNow = now.toString().split("T")[0]; storage.put("date", now); storage.put(new String[] { "lower", "date" }, now); storage.put(new String[] { "lower", "otherDate" }, dNow); Assert.assertEquals(dateNow, storage.get("date")); Assert.assertEquals(dateNow, storage.get(new String[] { "lower", "date" })); Assert.assertEquals(dNowString, storage.getString(new String[] { "lower", "otherDate" })); // for testing the parsing of an object with date time objects class Inner { public ZonedDateTime getDate() { return now; }//from w w w. j av a 2s . com public Date getOtherDate() { return dNow; } } class Top { public ZonedDateTime getDate() { return now; } public Inner getInner() { return new Inner(); } } Top test = new Top(); storage = new Storage(test); Assert.assertEquals(dateNow, storage.get("date")); Assert.assertEquals(dateNow, storage.get(new String[] { "inner", "date" })); Assert.assertEquals(dNowString, storage.get(new String[] { "inner", "otherDate" })); storage = new Storage(); storage.addModel(test); Assert.assertEquals(dateNow, storage.get("date")); Assert.assertEquals(dateNow, storage.get(new String[] { "inner", "date" })); Assert.assertEquals(dNowString, storage.get(new String[] { "inner", "otherDate" })); storage.put("test", test); Assert.assertEquals(dateNow, storage.get(new String[] { "test", "date" })); Assert.assertEquals(dateNow, storage.get(new String[] { "test", "inner", "date" })); Assert.assertEquals(dNowString, storage.get(new String[] { "test", "inner", "otherDate" })); //array list of objects that have DateTime ArrayList<Top> list = new ArrayList<>(); list.add(new Top()); list.add(new Top()); storage = new Storage(list); Assert.assertEquals(dateNow, storage.get(new String[] { "0", "date" })); Assert.assertEquals(dateNow, storage.get(new String[] { "1", "inner", "date" })); Assert.assertEquals(dNowString, storage.get(new String[] { "0", "inner", "otherDate" })); Assert.assertEquals("{\"date\":\"" + dateNow + "\",\"otherDate\":\"" + dNowString + "\"}", storage.getAsDataStorage(new String[] { "1", "inner" }).toString()); }
From source file:org.cgiar.ccafs.marlo.action.center.summaries.DeliverablesSummaryAction.java
/** * Get the main information of the report * /* w w w . ja va 2 s .c o m*/ * @return */ private TypedTableModel getMasterTableModel() { // Initialization of Model final TypedTableModel model = new TypedTableModel( new String[] { "currentDate", "center", "researchProgram" }, new Class[] { String.class, String.class, String.class }); String currentDate = ""; // Get datetime final ZonedDateTime timezone = ZonedDateTime.now(); final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm "); currentDate = timezone.format(format) + this.getTimeZone(); final String center = this.getCenterSession(); model.addRow(new Object[] { currentDate, center, researchProgram.getName() }); return model; }