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(Clock clock) 

Source Link

Document

Obtains the current date-time from the specified clock.

Usage

From source file:alfio.manager.TicketReservationManager.java

Stream<Event> getNotifiableEventsStream() {
    return eventRepository.findAll().stream().filter(e -> {
        int daysBeforeStart = configurationManager.getIntConfigValue(Configuration.from(e.getOrganizationId(),
                e.getId(), ConfigurationKeys.ASSIGNMENT_REMINDER_START), 10);
        //we don't want to define events SO far away, don't we?
        int days = (int) ChronoUnit.DAYS.between(ZonedDateTime.now(e.getZoneId()).toLocalDate(),
                e.getBegin().toLocalDate());
        return days > 0 && days <= daysBeforeStart;
    });//from w w  w .j  av  a  2  s .c  om
}

From source file:alfio.manager.TicketReservationManager.java

private void sendAssignmentReminder(Pair<Event, List<String>> p) {
    try {//from   w w  w .j av a  2s  .  c om
        requiresNewTransactionTemplate.execute(status -> {
            Event event = p.getLeft();
            ZoneId eventZoneId = event.getZoneId();
            int quietPeriod = configurationManager
                    .getIntConfigValue(Configuration.from(event.getOrganizationId(), event.getId(),
                            ConfigurationKeys.ASSIGNMENT_REMINDER_INTERVAL), 3);
            p.getRight().stream().map(id -> findByIdForNotification(id, eventZoneId, quietPeriod))
                    .filter(Optional::isPresent).map(Optional::get).forEach(reservation -> {
                        Map<String, Object> model = prepareModelForReservationEmail(event, reservation);
                        ticketReservationRepository.updateLatestReminderTimestamp(reservation.getId(),
                                ZonedDateTime.now(eventZoneId));
                        Locale locale = findReservationLanguage(reservation.getId());
                        notificationManager.sendSimpleEmail(event, reservation.getEmail(),
                                messageSource.getMessage("reminder.ticket-not-assigned.subject",
                                        new Object[] { event.getDisplayName() }, locale),
                                () -> templateManager.renderTemplate(event,
                                        TemplateResource.REMINDER_TICKETS_ASSIGNMENT_EMAIL, model, locale));
                    });
            return null;
        });
    } catch (Exception ex) {
        log.warn("cannot send reminder message", ex);
    }
}

From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java

@Test(description = "Event Observers for event listening")
public void testObserverEventListener() throws APIManagementException {

    EventLogger observer = Mockito.mock(EventLogger.class);

    APIPublisherImpl apiPub = getApiPublisherImpl();
    apiPub.registerObserver(observer);/*w  w  w .j a v a2  s.  c o m*/

    Event event = Event.APP_CREATION;
    String username = USER;
    Map<String, String> metaData = new HashMap<>();
    ZonedDateTime eventTime = ZonedDateTime.now(ZoneOffset.UTC);
    apiPub.notifyObservers(event, username, eventTime, metaData);

    Mockito.verify(observer, Mockito.times(1)).captureEvent(event, username, eventTime, metaData);

}