Example usage for java.time ZonedDateTime now

List of usage examples for java.time ZonedDateTime now

Introduction

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

Prototype

public static ZonedDateTime now() 

Source Link

Document

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

Usage

From source file:org.apache.james.jmap.utils.FilterToSearchQueryTest.java

@Test
public void filterConditionShouldMapWhenBefore() {
    ZonedDateTime before = ZonedDateTime.now();
    SearchQuery expectedSearchQuery = new SearchQuery();
    expectedSearchQuery/*from   w  ww  . j av  a 2  s. c  om*/
            .andCriteria(SearchQuery.internalDateBefore(Date.from(before.toInstant()), DateResolution.Second));

    SearchQuery searchQuery = new FilterToSearchQuery()
            .convert(FilterCondition.builder().before(before).build());

    assertThat(searchQuery).isEqualTo(expectedSearchQuery);
}

From source file:com.offbynull.peernetic.debug.visualizer.JGraphXVisualizer.java

@Override
public void step(String output, Command<A>... commands) {
    Validate.notNull(output);//from www. j  a v a  2  s .c  o m
    Validate.noNullElements(commands);

    String name = Thread.currentThread().getName();
    String dateStr = ZonedDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);

    textOutputArea.append(dateStr + " / " + name + " - " + output + " \n");
    textOutputArea.setCaretPosition(textOutputArea.getDocument().getLength());

    Recorder<A> rec = this.recorder.get();
    if (rec != null) {
        rec.recordStep(output, commands);
    }

    queueCommands(Arrays.asList(commands));
}

From source file:nu.yona.server.analysis.service.AnalysisEngineService.java

private void assertValidTimes(UserAnonymizedDto userAnonymized, String application,
        ZonedDateTime correctedStartTime, ZonedDateTime correctedEndTime) {
    if (correctedEndTime.isBefore(correctedStartTime)) {
        throw AnalysisException.appActivityStartAfterEnd(userAnonymized.getId(), application,
                correctedStartTime, correctedEndTime);
    }//from   w  w  w .  j  a v a 2s  . c om
    if (correctedStartTime.isAfter(ZonedDateTime.now().plus(DEVICE_TIME_INACCURACY_MARGIN))) {
        throw AnalysisException.appActivityStartsInFuture(userAnonymized.getId(), application,
                correctedStartTime);
    }
    if (correctedEndTime.isAfter(ZonedDateTime.now().plus(DEVICE_TIME_INACCURACY_MARGIN))) {
        throw AnalysisException.appActivityEndsInFuture(userAnonymized.getId(), application, correctedEndTime);
    }
}

From source file:org.codice.ddf.registry.federationadmin.service.impl.RegistryPublicationServiceImpl.java

@Override
public void update(Metacard metacard) throws FederationAdminException {

    List<String> publishedLocations = RegistryUtility.getListOfStringAttribute(metacard,
            RegistryObjectMetacardType.PUBLISHED_LOCATIONS);

    if (publishedLocations.isEmpty()) {
        return;//from w  ww  . j av  a  2 s  . c  o  m
    }

    Set<String> locations = publishedLocations.stream().map(registryId -> getSourceIdFromRegistryId(registryId))
            .filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new));

    if (CollectionUtils.isNotEmpty(locations)) {
        try {
            LOGGER.info("Updating publication for registry entry {}:{} at {}", metacard.getTitle(),
                    RegistryUtility.getRegistryId(metacard), String.join(",", locations));
            federationAdminService.updateRegistryEntry(metacard, locations);
        } catch (FederationAdminException e) {
            // This should not happen often but could occur if the remote registry removed the metacard
            // that was to be updated. In that case performing an add will fix the problem. If the
            // failure
            // was for another reason like the site couldn't be contacted then the add will fail
            // also and the end result will be the same.
            federationAdminService.addRegistryEntry(metacard, locations);
        }
        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED,
                Date.from(ZonedDateTime.now().toInstant())));
        federationAdminService.updateRegistryEntry(metacard);
    }
}

From source file:alfio.manager.CheckInManager.java

public boolean manualCheckIn(int eventId, String ticketIdentifier, String user) {
    Optional<Ticket> ticket = findAndLockTicket(ticketIdentifier);
    return ticket.map((t) -> {

        if (t.getStatus() == TicketStatus.TO_BE_PAID) {
            acquire(ticketIdentifier);// w  w  w. j  a va  2  s  . c o  m
        }

        checkIn(ticketIdentifier);
        scanAuditRepository.insert(ticketIdentifier, eventId, ZonedDateTime.now(), user, SUCCESS,
                ScanAudit.Operation.SCAN);
        auditingRepository.insert(t.getTicketsReservationId(),
                userRepository.findIdByUserName(user).orElse(null), eventId, Audit.EventType.MANUAL_CHECK_IN,
                new Date(), Audit.EntityType.TICKET, Integer.toString(t.getId()));
        return true;
    }).orElse(false);
}

From source file:org.edgexfoundry.scheduling.ScheduleContext.java

public boolean isComplete() {
    return isComplete(ZonedDateTime.now());
}

From source file:com.sumzerotrading.eod.trading.strategy.ReportGeneratorTest.java

@Test
public void testOrderEvent_RoundTripExists_ButNotComplete() throws Exception {
    RoundTrip roundTrip = new RoundTrip();
    TradeReferenceLine tradeReferenceLine = new TradeReferenceLine();
    tradeReferenceLine.correlationId = "123";
    tradeReferenceLine.direction = TradeReferenceLine.Direction.LONG;
    tradeReferenceLine.side = TradeReferenceLine.Side.ENTRY;
    roundTrip.addTradeReference(order, tradeReferenceLine);

    order.setCurrentStatus(OrderStatus.Status.FILLED);
    OrderEvent orderEvent = new OrderEvent(order,
            new OrderStatus(OrderStatus.Status.NEW, "", "", new StockTicker("QQQ"), ZonedDateTime.now()));

    TradeReferenceLine longExitLine = new TradeReferenceLine();
    longExitLine.correlationId = "123";
    longExitLine.direction = TradeReferenceLine.Direction.LONG;
    longExitLine.side = TradeReferenceLine.Side.EXIT;

    reportGenerator.roundTripMap.put("123", roundTrip);

    doReturn(longExitLine).when(reportGenerator).getTradeReferenceLine(any(String.class));
    doNothing().when(reportGenerator).savePartial(any(String.class), any(RoundTrip.class));
    assertEquals(1, reportGenerator.roundTripMap.size());

    reportGenerator.orderEvent(orderEvent);

    verify(reportGenerator).savePartial("123", roundTrip);
    verify(reportGenerator, never()).writeRoundTripToFile(any(RoundTrip.class));

    assertEquals(1, reportGenerator.roundTripMap.size());
}

From source file:com.sumzerotrading.reporting.csv.ReportGeneratorTest.java

@Test
public void testOrderEvent_FirstRoundTrip() throws Exception {
    TradeReferenceLine tradeReferenceLine = new TradeReferenceLine();
    tradeReferenceLine.setCorrelationId("123");
    tradeReferenceLine.setStrategy(strategy);
    order.setCurrentStatus(OrderStatus.Status.FILLED);
    OrderEvent orderEvent = new OrderEvent(order,
            new OrderStatus(OrderStatus.Status.NEW, "", "", new StockTicker("QQQ"), ZonedDateTime.now()));

    doReturn(tradeReferenceLine).when(reportGenerator).getTradeReferenceLine(any(String.class));
    doNothing().when(reportGenerator).savePartial(any(String.class), any(PairTradeRoundTrip.class));
    assertTrue(reportGenerator.roundTripMap.isEmpty());

    reportGenerator.orderEvent(orderEvent);

    verify(reportGenerator).savePartial(eq("123"), any(PairTradeRoundTrip.class));
    verify(reportGenerator, never()).writeRoundTripToFile(any(PairTradeRoundTrip.class));
    assertEquals(1, reportGenerator.roundTripMap.size());
}

From source file:com.sumzerotrading.intraday.trading.strategy.ReportGeneratorTest.java

@Test
public void testOrderEvent_RoundTripExists_ButNotComplete() throws Exception {
    RoundTrip roundTrip = new RoundTrip();
    TradeReferenceLine tradeReferenceLine = new TradeReferenceLine();
    tradeReferenceLine.correlationId = "123";
    tradeReferenceLine.direction = TradeReferenceLine.Direction.LONG;
    tradeReferenceLine.side = TradeReferenceLine.Side.ENTRY;

    roundTrip.addTradeReference(order, tradeReferenceLine);

    order.setCurrentStatus(OrderStatus.Status.FILLED);
    OrderEvent orderEvent = new OrderEvent(order,
            new OrderStatus(OrderStatus.Status.NEW, "", "", new StockTicker("QQQ"), ZonedDateTime.now()));

    reportGenerator.roundTripMap.put("123", roundTrip);

    doReturn(tradeReferenceLine).when(reportGenerator).getTradeReferenceLine(order.getReference());
    doNothing().when(reportGenerator).savePartial(any(String.class), any(RoundTrip.class));
    assertEquals(1, reportGenerator.roundTripMap.size());

    reportGenerator.orderEvent(orderEvent);

    verify(reportGenerator).savePartial("123", roundTrip);
    verify(reportGenerator, never()).writeRoundTripToFile(any(RoundTrip.class));

    assertEquals(1, reportGenerator.roundTripMap.size());
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testDistributeSeatsFirstCategoryIsUnbounded() throws Exception {
    List<TicketCategoryModification> categories = getPreSalesTicketCategoryModifications(false, AVAILABLE_SEATS,
            true, 10);/*from w  ww.ja va2s .co m*/
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);
    Event event = pair.getKey();
    TicketCategory firstCategory = eventManager.loadTicketCategories(event).stream()
            .filter(t -> t.getName().equals("defaultFirst")).findFirst()
            .orElseThrow(IllegalStateException::new);
    configurationManager.saveCategoryConfiguration(firstCategory.getId(), event.getId(),
            Collections.singletonList(new ConfigurationModification(null,
                    ConfigurationKeys.MAX_AMOUNT_OF_TICKETS_BY_RESERVATION.getValue(), "1")),
            pair.getRight() + "_owner");
    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_PRE_REGISTRATION, "true");
    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
    boolean result = waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null,
            Locale.ENGLISH);
    assertTrue(result);
    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(firstCategory.getId()), reservation.getTicketCategoryId());
    assertEquals(Integer.valueOf(1), reservation.getAmount());
    assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now()));

}