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.controller.api.admin.AdminWaitingQueueApiController.java

private Map<String, Boolean> loadStatus(Event event) {
    ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    List<SaleableTicketCategory> stcList = eventManager.loadTicketCategories(event).stream()
            .filter(tc -> !tc.isAccessRestricted())
            .map(tc -> new SaleableTicketCategory(tc, "", now, event,
                    ticketReservationManager.countAvailableTickets(event, tc), tc.getMaxTickets(), null))
            .collect(Collectors.toList());
    boolean active = EventUtil.checkWaitingQueuePreconditions(event, stcList, configurationManager,
            eventStatisticsManager.noSeatsAvailable());
    boolean paused = active && configurationManager.getBooleanConfigValue(
            Configuration.from(event.getOrganizationId(), event.getId(), STOP_WAITING_QUEUE_SUBSCRIPTIONS),
            false);/*  ww  w. ja va2s  .co  m*/
    Map<String, Boolean> result = new HashMap<>();
    result.put("active", active);
    result.put("paused", paused);
    return result;
}

From source file:ch.digitalfondue.npjt.query.DateTimeQueriesTest.java

@Test
public void dateQueriesTest() {
    QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource));

    qf.addColumnMapperFactory(new ZonedDateTimeMapper.Factory());
    qf.addParameterConverters(new ZonedDateTimeMapper.Converter());

    qf.addColumnMapperFactory(new LocalDateMapper.Factory());
    qf.addParameterConverters(new LocalDateMapper.Converter());

    qf.addColumnMapperFactory(new LocalDateTimeMapper.Factory());
    qf.addParameterConverters(new LocalDateTimeMapper.Converter());

    qf.addColumnMapperFactory(new InstantMapper.Factory());
    qf.addParameterConverters(new InstantMapper.Converter());

    DateQueries dq = qf.from(DateQueries.class);

    dq.createTable();//  w w  w.  j a va 2  s  .  c o  m

    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));

    dq.insertValue("KEY", now);
    check(dq, "KEY", now);

    dq.insertValue("KEY2", now.toLocalDate());
    check(dq, "KEY2", now.toLocalDate());

    dq.insertValue("KEY3", now.toLocalDateTime());
    check(dq, "KEY3", now);

    Instant iNow = Instant.now();
    dq.insertValue("KEY4", iNow);
    Assert.assertEquals(iNow, dq.findInstantByKey("KEY4"));
    Assert.assertEquals(iNow, dq.findConfInstantByKey("KEY4").value);

}

From source file:no.digipost.api.useragreements.client.response.ResponseUtilsTest.java

@Test
public void parsesDateFromRetryAfterHeader() {
    Clock clock = Clock.fixed(Instant.now().truncatedTo(SECONDS), ZoneOffset.UTC);
    HttpResponse tooManyRequestsErrorResponse = tooManyRequestsResponseWithRetryAfter(
            RFC_1123_DATE_TIME.format(ZonedDateTime.now(clock).plusSeconds(42)));

    Optional<Duration> parsedDuration = ResponseUtils
            .parseDelayDurationOfRetryAfterHeader(tooManyRequestsErrorResponse, clock);
    assertThat(parsedDuration, contains(Duration.ofSeconds(42)));
}

From source file:io.stallion.jobs.Schedule.java

/**
 * Gets the next datetime matching the schedule, in the Users timezone
 *
 * @return//from  w  w  w .ja va  2 s.com
 */
public ZonedDateTime nextAt() {
    ZoneId zoneId = null;
    if (!StringUtils.isEmpty(timeZoneId)) {
        zoneId = ZoneId.of(timeZoneId);
    } else if (timeZoneForUserId != null) {
        IUser user = UserController.instance().forId(timeZoneForUserId);
        if (user != null && !StringUtils.isEmpty(user.getTimeZoneId())) {
            zoneId = ZoneId.of(user.getTimeZoneId());
        }
    }

    if (zoneId == null) {
        zoneId = ZoneId.of("UTC");
    }
    ZonedDateTime dt = ZonedDateTime.now(zoneId);
    return nextAt(dt);
}

From source file:org.clebi.subscribers.daos.SubscribersIntegTestHelper.java

protected Map<String, Subscriber> indexTestSubscibers(String index) {
    final Map<String, Subscriber> subscribers = new HashMap<>();
    final String emailOptinActive = "optin_active_0@test.com";
    final String emailOptinNonActive = "optin_non-active_0@test.com";
    final String emailNonOptinActive = "non-optin-active_0@test.com";
    final String emailNonOptinNonActiv = "non-optin-non-active_0@test.com";
    subscribers.put(emailOptinActive, new Subscriber(true, true, new Email(emailOptinActive),
            ZonedDateTime.now(ZoneOffset.UTC), generateTestFields()));
    subscribers.put(emailOptinNonActive, new Subscriber(true, false, new Email(emailOptinNonActive),
            ZonedDateTime.now(ZoneOffset.UTC), generateTestFields()));
    subscribers.put(emailNonOptinActive, new Subscriber(false, true, new Email(emailNonOptinActive),
            ZonedDateTime.now(ZoneOffset.UTC), generateTestFields()));
    subscribers.put(emailNonOptinNonActiv, new Subscriber(false, false, new Email(emailNonOptinNonActiv),
            ZonedDateTime.now(ZoneOffset.UTC), generateTestFields()));
    for (Map.Entry<String, Subscriber> entry : subscribers.entrySet()) {
        indexSubsciber(index, entry.getValue());
    }/*  w  ww . j a  va2 s  .  co m*/
    return subscribers;
}

From source file:keywhiz.auth.cookie.AuthenticatedEncryptedCookieFactory.java

/**
 * Produces a cookie string for a given value and expiration.
 *
 * @param value value of new cookie.//  w  w  w . j  a  v a 2 s.  c om
 * @param expiration expiration time of cookie.
 * @return serialized cookie with given value and expiration.
 */
public NewCookie cookieFor(String value, ZonedDateTime expiration) {
    long maxAge = Duration.between(ZonedDateTime.now(clock), expiration).getSeconds();

    HttpCookie cookie = new HttpCookie(config.getName(), value, config.getDomain(), config.getPath(), maxAge,
            config.isHttpOnly(), config.isSecure());

    Response response = new Response(null, null);
    response.addCookie(cookie);
    return NewCookie.valueOf(response.getHttpFields().getStringField(HttpHeader.SET_COOKIE));
}

From source file:alfio.util.EventUtil.java

public static boolean isPreSales(Event event, List<SaleableTicketCategory> categories) {
    ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    return findFirstCategory(categories).map(c -> now.isBefore(c.getZonedInception())).orElse(false);
}

From source file:io.stallion.jobs.Schedule.java

/**
 * Gets the next datetime matching the schedule, in the application timezone, as defined in the settings
 *
 * @return//w w  w  .  ja  v a 2s .  com
 */
public ZonedDateTime serverLocalNextAt() {
    ZoneId zoneId = null;
    if (zoneId == null) {
        zoneId = Context.getSettings().getTimeZoneId();
    }
    if (zoneId == null) {
        zoneId = ZoneId.of("UTC");
    }
    ZonedDateTime dt = ZonedDateTime.now(zoneId);
    return nextAt(dt);
}

From source file:alfio.manager.WaitingQueueManager.java

public boolean subscribe(Event event, CustomerName customerName, String email, Integer selectedCategoryId,
        Locale userLanguage) {/*from w w w  .  j  ava  2  s  .c om*/
    try {
        if (configurationManager.getBooleanConfigValue(
                Configuration.from(event.getOrganizationId(), event.getId(), STOP_WAITING_QUEUE_SUBSCRIPTIONS),
                false)) {
            log.info("waiting queue subscription denied for event {} ({})", event.getShortName(),
                    event.getId());
            return false;
        }
        WaitingQueueSubscription.Type subscriptionType = getSubscriptionType(event);
        validateSubscriptionType(event, subscriptionType);
        validateSelectedCategoryId(event.getId(), selectedCategoryId);
        AffectedRowCountAndKey<Integer> key = waitingQueueRepository.insert(event.getId(),
                customerName.getFullName(), customerName.getFirstName(), customerName.getLastName(), email,
                ZonedDateTime.now(event.getZoneId()), userLanguage.getLanguage(), subscriptionType,
                selectedCategoryId);
        notifySubscription(event, customerName, email, userLanguage, subscriptionType);
        pluginManager.handleWaitingQueueSubscription(waitingQueueRepository.loadById(key.getKey()));
        extensionManager.handleWaitingQueueSubscription(waitingQueueRepository.loadById(key.getKey()));
        return true;
    } catch (DuplicateKeyException e) {
        return true;//why are you subscribing twice?
    } catch (Exception e) {
        log.error("error during subscription", e);
        return false;
    }
}

From source file:nu.yona.server.batch.jobs.ActivityAggregationBatchJob.java

@Bean(name = "activityAggregationJobDayActivityReader", destroyMethod = "")
@StepScope/*from   ww w .  j a v a  2  s .  c o m*/
public ItemReader<Long> dayActivityReader() {
    return intervalActivityIdReader(Date.valueOf(TimeUtil
            .getStartOfDay(DEFAULT_TIME_ZONE, ZonedDateTime.now(DEFAULT_TIME_ZONE)).minusDays(1).toLocalDate()),
            DayActivity.class, DAY_ACTIVITY_CHUNK_SIZE);
}