Search in sources :

Example 81 with ZonedDateTime

use of java.time.ZonedDateTime in project presto by prestodb.

the class AtopSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) {
    AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle;
    AtopTableHandle table = handle.getTableHandle();
    List<ConnectorSplit> splits = new ArrayList<>();
    ZonedDateTime end = ZonedDateTime.now(timeZone);
    for (Node node : nodeManager.getWorkerNodes()) {
        ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        while (start.isBefore(end)) {
            ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0);
            Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false);
            if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) {
                splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone()));
            }
            start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        }
    }
    return new FixedSplitSource(splits);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Node(com.facebook.presto.spi.Node) ArrayList(java.util.ArrayList) Domain(com.facebook.presto.spi.predicate.Domain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 82 with ZonedDateTime

use of java.time.ZonedDateTime in project siddhi by wso2.

the class IncrementalTimeConverterUtil method getStartTimeOfPreviousMonth.

private static long getStartTimeOfPreviousMonth(long currentEmitTime, String timeZone) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentEmitTime), ZoneId.ofOffset("GMT", ZoneOffset.of(timeZone)));
    int givenMonth = zonedDateTime.getMonthValue();
    int givenYear = zonedDateTime.getYear();
    if (givenMonth == 1) {
        return ZonedDateTime.of(--givenYear, 12, 1, 0, 0, 0, 0, ZoneId.ofOffset("GMT", ZoneOffset.of(timeZone))).toEpochSecond() * 1000;
    } else {
        return ZonedDateTime.of(givenYear, --givenMonth, 1, 0, 0, 0, 0, ZoneId.ofOffset("GMT", ZoneOffset.of(timeZone))).toEpochSecond() * 1000;
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime)

Example 83 with ZonedDateTime

use of java.time.ZonedDateTime in project siddhi by wso2.

the class IncrementalTimeConverterUtil method getStartTimeOfPreviousYear.

private static long getStartTimeOfPreviousYear(long currentEmitTime, String timeZone) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentEmitTime), ZoneId.ofOffset("GMT", ZoneOffset.of(timeZone)));
    int givenYear = zonedDateTime.getYear();
    return ZonedDateTime.of(--givenYear, 1, 1, 0, 0, 0, 0, ZoneId.ofOffset("GMT", ZoneOffset.of(timeZone))).toEpochSecond() * 1000;
}
Also used : ZonedDateTime(java.time.ZonedDateTime)

Example 84 with ZonedDateTime

use of java.time.ZonedDateTime in project cas by apereo.

the class DateTimeAuthenticationRequestRiskCalculator method calculateScore.

@Override
protected BigDecimal calculateScore(final HttpServletRequest request, final Authentication authentication, final RegisteredService service, final Collection<CasEvent> events) {
    final ZonedDateTime timestamp = ZonedDateTime.now(ZoneOffset.UTC);
    LOGGER.debug("Filtering authentication events for timestamp [{}]", timestamp);
    final int hoursFromNow = timestamp.plusHours(windowInHours).getHour();
    final int hoursBeforeNow = timestamp.minusHours(windowInHours).getHour();
    final long count = events.stream().map(time -> {
        final Instant instant = ChronoZonedDateTime.from(time.getCreationTime()).toInstant();
        final ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
        return zdt.getHour();
    }).filter(hour -> hour <= hoursFromNow && hour >= hoursBeforeNow).count();
    LOGGER.debug("Total authentication events found for [{}] in a [{}]h window: [{}]", timestamp, windowInHours, count);
    if (count == events.size()) {
        LOGGER.debug("Principal [{}] has always authenticated from [{}]", authentication.getPrincipal(), timestamp);
        return LOWEST_RISK_SCORE;
    }
    return getFinalAveragedScore(count, events.size());
}
Also used : CasEventRepository(org.apereo.cas.support.events.CasEventRepository) BigDecimal(java.math.BigDecimal) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) Authentication(org.apereo.cas.authentication.Authentication) ZonedDateTime(java.time.ZonedDateTime) Collection(java.util.Collection) ZoneOffset(java.time.ZoneOffset) Instant(java.time.Instant) RegisteredService(org.apereo.cas.services.RegisteredService) CasEvent(org.apereo.cas.support.events.dao.CasEvent) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant)

Example 85 with ZonedDateTime

use of java.time.ZonedDateTime in project cas by apereo.

the class ThrottledUseAndTimeoutExpirationPolicy method isExpired.

@Override
public boolean isExpired(final TicketState ticketState) {
    final ZonedDateTime currentTime = ZonedDateTime.now(ZoneOffset.UTC);
    final ZonedDateTime lastTimeUsed = ticketState.getLastTimeUsed();
    final ZonedDateTime killTime = lastTimeUsed.plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
    if (ticketState.getCountOfUses() == 0 && currentTime.isBefore(killTime)) {
        LOGGER.debug("Ticket is not expired due to a count of zero and the time being less " + "than the timeToKillInSeconds");
        return super.isExpired(ticketState);
    }
    if (currentTime.isAfter(killTime)) {
        LOGGER.debug("Ticket is expired due to the time being greater than the timeToKillInSeconds");
        return true;
    }
    final ZonedDateTime dontUseUntil = lastTimeUsed.plus(this.timeInBetweenUsesInSeconds, ChronoUnit.SECONDS);
    if (currentTime.isBefore(dontUseUntil)) {
        LOGGER.warn("Ticket is expired due to the time being less than the waiting period.");
        return true;
    }
    return super.isExpired(ticketState);
}
Also used : ZonedDateTime(java.time.ZonedDateTime)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1375 Test (org.junit.Test)570 Test (org.testng.annotations.Test)182 LocalDateTime (java.time.LocalDateTime)136 ZoneId (java.time.ZoneId)122 Instant (java.time.Instant)112 ArrayList (java.util.ArrayList)102 Test (org.junit.jupiter.api.Test)93 LocalDate (java.time.LocalDate)84 DateTimeFormatter (java.time.format.DateTimeFormatter)77 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)76 List (java.util.List)75 Date (java.util.Date)63 IOException (java.io.IOException)58 UUID (java.util.UUID)58 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)53 HashMap (java.util.HashMap)46 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)43