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);
}
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;
}
}
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;
}
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());
}
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);
}
Aggregations