public ZonedDateTime minusSeconds(long amount) { return dt.minusSeconds(amount); }
/** * Returns a {@link java.time.ZonedDateTime} that is {@code seconds} seconds before this date/time. * * @param self a ZonedDateTime * @param seconds the number of seconds to subtract * @return a ZonedDateTime * @since 2.5.0 */ public static ZonedDateTime minus(final ZonedDateTime self, long seconds) { return self.minusSeconds(seconds); }
@Override public void decreaseExpiresAt(int decreaseSeconds) { expiresAt = expiresAt.minusSeconds(decreaseSeconds); }
public ZonedDateTime minusSeconds(long amount) { return dt.minusSeconds(amount); }
public ZonedDateTime minusSeconds(long amount) { return dt.minusSeconds(amount); }
ZonedDateTime java8DateTime = ZonedDateTime.now(); // uses ZoneId.systemDefault() ZonedDateTime java8DateTimeInPast = java8DateTime.minusSeconds(60); doSomething(java8DateTimeInPast.toInstant());
/** * Gets failure in range cut off date. * * @return the failure in range cut off date */ protected Date getFailureInRangeCutOffDate() { val cutoff = ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(getFailureRangeInSeconds()); return DateTimeUtils.timestampOf(cutoff); }
private static Map<String, Object> generateApacheLog() { Map<String,Object> map = new HashMap<>(); String datetime = ZonedDateTime.now().minusSeconds(random.nextInt(3000)).format(DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z")); String ip = faker.internet().ipV4Address(); String method = getRandomItemFromList(methods); String response = getRandomItemFromList(responses); String resource = "/" + String.join("/", resources.subList(random.nextInt(5), 4 + random.nextInt(5))); String ua = getRandomItemFromList(userAgents); String bytes = String.valueOf(random.nextInt(5000)); String referrer = faker.internet().url(); map.put("message", String.format("%s - - [%s] \"%s %s HTTP/1.1\" %s %s \"%s\" \"%s\"",ip, datetime, method, resource, response, bytes, referrer, ua)); return map; }
void addItinerary(Integer accessIdx, Integer egressIdx, List<TransitJourneyID> transitJourneyIDs, ZoneId timeZone) { Itinerary itinerary = new Itinerary(); itinerary.transfers = transitJourneyIDs.size() - 1; itinerary.walkTime = access.get(accessIdx).duration+egress.get(egressIdx).duration; itinerary.distance = access.get(accessIdx).distance+egress.get(egressIdx).distance; ZonedDateTime transitStart = transit.get(0).segmentPatterns.get(transitJourneyIDs.get(0).pattern).fromDepartureTime.get(transitJourneyIDs.get(0).time); itinerary.startTime = transitStart.minusSeconds(access.get(accessIdx).duration); int lastTransit = transitJourneyIDs.size()-1; ZonedDateTime transitStop = transit.get(lastTransit).segmentPatterns.get(transitJourneyIDs.get(lastTransit).pattern).toArrivalTime.get(transitJourneyIDs.get(lastTransit).time); itinerary.endTime = transitStop.plusSeconds(egress.get(egressIdx).duration); itinerary.duration = (int) Duration.between(itinerary.startTime,itinerary.endTime).getSeconds(); itinerary.transitTime = 0; int transitJourneyIDIdx=0; for(TransitJourneyID transitJourneyID: transitJourneyIDs) { itinerary.transitTime += transit.get(transitJourneyIDIdx).getTransitTime(transitJourneyID); transitJourneyIDIdx++; } itinerary.waitingTime=itinerary.duration-(itinerary.transitTime+itinerary.walkTime); PointToPointConnection pointToPointConnection = new PointToPointConnection(accessIdx, egressIdx, transitJourneyIDs); itinerary.addConnection(pointToPointConnection); this.itinerary.add(itinerary); }
void addItinerary(Integer accessIdx, Integer egressIdx, List<TransitJourneyID> transitJourneyIDs, ZoneId timeZone) { Itinerary itinerary = new Itinerary(); itinerary.transfers = transitJourneyIDs.size() - 1; itinerary.walkTime = access.get(accessIdx).duration+egress.get(egressIdx).duration; itinerary.distance = access.get(accessIdx).distance+egress.get(egressIdx).distance; ZonedDateTime transitStart = transit.get(0).segmentPatterns.get(transitJourneyIDs.get(0).pattern).fromDepartureTime.get(transitJourneyIDs.get(0).time); itinerary.startTime = transitStart.minusSeconds(access.get(accessIdx).duration); int lastTransit = transitJourneyIDs.size()-1; ZonedDateTime transitStop = transit.get(lastTransit).segmentPatterns.get(transitJourneyIDs.get(lastTransit).pattern).toArrivalTime.get(transitJourneyIDs.get(lastTransit).time); itinerary.endTime = transitStop.plusSeconds(egress.get(egressIdx).duration); itinerary.duration = (int) Duration.between(itinerary.startTime,itinerary.endTime).getSeconds(); itinerary.transitTime = 0; int transitJourneyIDIdx=0; for(TransitJourneyID transitJourneyID: transitJourneyIDs) { itinerary.transitTime += transit.get(transitJourneyIDIdx).getTransitTime(transitJourneyID); transitJourneyIDIdx++; } itinerary.waitingTime=itinerary.duration-(itinerary.transitTime+itinerary.walkTime); PointToPointConnection pointToPointConnection = new PointToPointConnection(accessIdx, egressIdx, transitJourneyIDs); itinerary.addConnection(pointToPointConnection); this.itinerary.add(itinerary); }
@Override protected void renderMergedOutputModel(final Map<String, Object> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { try { response.setCharacterEncoding(this.encoding); val service = this.samlArgumentExtractor.extractService(request); val serviceId = getServiceIdFromRequest(service); LOGGER.debug("Using [{}] as the recipient of the SAML response for [{}]", serviceId, service); val samlResponse = this.samlObjectBuilder.newResponse( this.samlObjectBuilder.generateSecureRandomId(), ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(this.skewAllowance), serviceId, service); LOGGER.debug("Created SAML response for service [{}]", serviceId); prepareResponse(samlResponse, model); LOGGER.debug("Starting to encode SAML response for service [{}]", serviceId); this.samlObjectBuilder.encodeSamlResponse(response, request, samlResponse); } catch (final Exception e) { LOGGER.error("Error generating SAML response for service", e); throw e; } }
/** * Provide nearest date for last execution. * * @param date - ZonedDateTime instance. If null, a NullPointerException will be raised. * @return Optional ZonedDateTime instance, never null. Last execution time or empty. */ public Optional<ZonedDateTime> lastExecution(final ZonedDateTime date) { Preconditions.checkNotNull(date); try { ZonedDateTime previousMatch = previousClosestMatch(date); if (previousMatch.equals(date)) { previousMatch = previousClosestMatch(date.minusSeconds(1)); } return Optional.of(previousMatch); } catch (final NoSuchValueException e) { return Optional.empty(); } }
/** * {@inheritDoc} * The CRL next update time is compared against the current time with the threshold * applied and rejected if and only if the next update time is in the past. * * @param crl CRL instance to evaluate. * @throws ExpiredCRLException On expired CRL data. Check the exception type for exact details */ @Override public void apply(final X509CRL crl) throws ExpiredCRLException { val cutoff = ZonedDateTime.now(ZoneOffset.UTC); if (CertUtils.isExpired(crl, cutoff)) { if (CertUtils.isExpired(crl, cutoff.minusSeconds(this.threshold))) { throw new ExpiredCRLException(crl.toString(), cutoff, this.threshold); } LOGGER.info(String.format("CRL expired on %s but is within threshold period, %s seconds.", crl.getNextUpdate(), this.threshold)); } } }
@Test public void testSet() { SonarLintProjectState state = new SonarLintProjectState(); state.setLastEventPolling(ZonedDateTime.now()); assertThat(state.getLastEventPolling()).isBeforeOrEqualTo(ZonedDateTime.now()); assertThat(state.getLastEventPolling()).isAfter(ZonedDateTime.now().minusSeconds(3)); }
@Test public void queryForCreatedAtIsGreaterThan() { createdAtTest((m, date) -> m.isGreaterThan(date.minusSeconds(1))); }
@Test public void queryForCreatedAtIsGreaterThanOrEqualTo() { createdAtTest((m, date) -> m.isGreaterThanOrEqualTo(date.minusSeconds(1))); }
private static ExecutionTimeResult getPreviousPotentialValue( final ZonedDateTime date, final TimeNode node, final TemporalField field) throws NoSuchValueException { Set<Integer> values = new HashSet<>(node.values); TemporalUnit unit = field.getBaseUnit(); long maximum = field.range().getMaximum(); long minimum = field.range().getMinimum(); long range = maximum - minimum; ZonedDateTime newDate = date; for (long i = 0; i < 2 * range; i++) { newDate = newDate.minus(1, unit); if (values.contains(newDate.get(field))) { newDate = newDate .truncatedTo(unit) .plus(1, unit) .minusSeconds(1); return new ExecutionTimeResult(newDate, false); } } throw new NoSuchValueException(); }
public Health getHealth() { HealthCheckConfiguration healthCheckConfiguration = configuration.getHealthCheckConfiguration(); ZonedDateTime currentTime = currentTimeSupplier.get(); ZonedDateTime xSecondsAgo = currentTime.minusSeconds(healthCheckConfiguration.getTimeRangeInSeconds()); OperationFilter filter = new OperationFilter.Builder().mtaId(healthCheckConfiguration.getMtaId()) .spaceId(healthCheckConfiguration.getSpaceId()) .user(healthCheckConfiguration.getUserName()) .endedAfter(Date.from(xSecondsAgo.toInstant())) .inFinalState() .orderByEndTime() .descending() .build(); List<Operation> healthCheckOperations = operationDao.find(filter); return Health.fromOperations(healthCheckOperations); }
@Test public void getCompletedAt() throws Exception { final ZonedDateTime completedAt = SphereTestUtils.now().minusSeconds(5555); testOrderAspect(builder -> builder.completedAt(completedAt), order -> assertThat(order.getCompletedAt()).isEqualTo(completedAt)); }
@Test public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusSeconds(1); String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT); Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time)); Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1)); DateTimeWithinPeriod func = new DateTimeWithinPeriod(); assertEquals(TRUE, func.evaluate(VF, now, now, VF.createLiteral(1), OWLTime.SECONDS_URI)); assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(1), OWLTime.SECONDS_URI)); assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(2), OWLTime.SECONDS_URI)); }