Example usage for java.time ZonedDateTime isBefore

List of usage examples for java.time ZonedDateTime isBefore

Introduction

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

Prototype

default boolean isBefore(ChronoZonedDateTime<?> other) 

Source Link

Document

Checks if the instant of this date-time is before that of the specified date-time.

Usage

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:alfio.util.EventUtil.java

public static boolean checkWaitingQueuePreconditions(Event event, List<SaleableTicketCategory> categories,
        ConfigurationManager configurationManager, Predicate<Event> noTicketsAvailable) {
    return findLastCategory(categories).map(lastCategory -> {
        ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
        if (isPreSales(event, categories)) {
            return configurationManager.getBooleanConfigValue(
                    Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_PRE_REGISTRATION),
                    false);//from w ww. j  ava 2  s.co  m
        } else if (configurationManager.getBooleanConfigValue(
                Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_WAITING_QUEUE), false)) {
            return now.isBefore(lastCategory.getZonedExpiration()) && noTicketsAvailable.test(event);
        }
        return false;
    }).orElse(false);
}

From source file:ru.anr.base.BaseParent.java

/**
 * Checks the given date-time object was in the past
 * //from ww w.java 2s.  c  o m
 * @param z
 *            Some date-time object
 * @return true, if the given date was in the past comparing with the
 *         present time
 */
public static boolean inPast(ZonedDateTime z) {

    return z.isBefore(now());
}

From source file:alfio.controller.api.support.PublicCategory.java

public boolean isActive() {
    ZonedDateTime now = ZonedDateTime.now(Clock.systemUTC());
    return category.getUtcInception().isBefore(now) && now.isBefore(category.getUtcExpiration());
}

From source file:io.stallion.services.SecureTempTokens.java

public TempToken getOrCreate(String key, ZonedDateTime expiresAt) {
    List<TempToken> tokens = DB.instance().queryBean(TempToken.class,
            "SELECT * FROM stallion_temp_tokens WHERE customKey=? LIMIT 1", key);

    TempToken token = null;/*from   ww w  .  j  a  va2s  .  co m*/
    if (tokens.size() > 0) {
        token = tokens.get(0);
    }
    ZonedDateTime now = DateUtils.utcNow();
    // If the token has already been used or is expired, we generate a new token
    if (token != null && token.getUsedAt() == null && now.isBefore(token.getExpiresAt())) {
        return token;
    }
    if (token == null) {
        token = new TempToken();
        token.setId(Context.dal().getTickets().nextId());
    }
    token.setCreatedAt(now);
    token.setExpiresAt(expiresAt);
    token.setCustomKey(key);
    token.setToken(idToRandomString((Long) token.getId()));
    token.setUsedAt(null);
    DB.instance().save(token);
    return token;
}

From source file:com.match_tracker.twitter.TwitterSearch.java

protected long calculateSearchDelay(ZonedDateTime startTime) {
    long searchDelay = 0;

    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    ZonedDateTime offsetStartTime = startTime.plusSeconds(SEARCH_START_DELAY_SECONDS);

    if (now.isBefore(offsetStartTime)) {
        searchDelay = now.until(offsetStartTime, ChronoUnit.MILLIS);
    }//from   w  w  w  .j a  v a2  s  .  com

    return searchDelay;
}

From source file:com.netflix.spinnaker.front50.model.SwiftStorageService.java

@Override
public long getLastModified(ObjectType objectType) {
    List<? extends SwiftObject> objects = getSwift().objects().list(containerName,
            ObjectListOptions.create().path(objectType.group));
    ZonedDateTime lastModified = Instant.now().atZone(ZoneOffset.UTC);
    for (SwiftObject o : objects) {
        ZonedDateTime timestamp = ZonedDateTime.parse(
                getSwift().objects().getMetadata(containerName, o.getName()).get("Last-Modified"),
                DateTimeFormatter.RFC_1123_DATE_TIME);
        if (timestamp.isBefore(lastModified)) {
            lastModified = timestamp;//w  w w .ja v  a2 s  .  co  m
        }
    }
    return lastModified.toEpochSecond();
}

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  2 s.c  o  m*/
    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:alfio.manager.WaitingQueueManager.java

private WaitingQueueSubscription.Type getSubscriptionType(Event event) {
    ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    return ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst()
            .filter(tc -> now.isBefore(tc.getInception(event.getZoneId())))
            .map(tc -> WaitingQueueSubscription.Type.PRE_SALES).orElse(WaitingQueueSubscription.Type.SOLD_OUT);
}

From source file:alfio.manager.EventManager.java

private void fixTicketCategoryDates(ZonedDateTime end, TicketCategory tc, ZonedDateTime inception,
        ZonedDateTime expiration) {
    final ZonedDateTime newExpiration = ObjectUtils.min(end, expiration);
    Objects.requireNonNull(newExpiration);
    Validate.isTrue(inception.isBefore(newExpiration),
            format("Cannot fix dates for category \"%s\" (id: %d), try updating that category first.",
                    tc.getName(), tc.getId()));
    ticketCategoryRepository.fixDates(tc.getId(), inception, newExpiration);
}