Java Code Examples for java.time.ZonedDateTime#isAfter()

The following examples show how to use java.time.ZonedDateTime#isAfter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpaAction.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isMaintenanceWindowAvailable() {
    if (!hasMaintenanceSchedule()) {
        // if there is no defined maintenance schedule, a window is always
        // available.
        return true;
    } else if (isMaintenanceScheduleLapsed()) {
        // if a defined maintenance schedule has lapsed, a window is never
        // available.
        return false;
    } else {
        final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.of(maintenanceWindowTimeZone));
        final Optional<ZonedDateTime> start = getMaintenanceWindowStartTime();
        final Optional<ZonedDateTime> end = getMaintenanceWindowEndTime();

        if (start.isPresent() && end.isPresent()) {
            return now.isAfter(start.get()) && now.isBefore(end.get());
        } else {
            return false;
        }
    }
}
 
Example 2
Source File: RangeFilterTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "ZonedDateTimeRanges")
public void testRangeOfZonedDateTimes(ZonedDateTime start, ZonedDateTime end, Duration step, boolean parallel) {
    final boolean ascend = start.isBefore(end);
    final Range<ZonedDateTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
    final Array<ZonedDateTime> array = range.toArray(parallel);
    final ZonedDateTime first = array.first(v -> true).map(ArrayValue::getValue).get();
    final ZonedDateTime last = array.last(v -> true).map(ArrayValue::getValue).get();
    Assert.assertEquals(array.typeCode(), ArrayType.ZONED_DATETIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    int index = 0;
    ZonedDateTime value = first;
    while (ascend ? value.isBefore(last) : value.isAfter(last)) {
        final ZonedDateTime actual = array.getValue(index);
        Assert.assertEquals(actual, value, "Value matches at " + index);
        Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
        value = ascend ? value.plus(step) : value.minus(step);
        while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
        index++;
    }
}
 
Example 3
Source File: FileMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
private void getArtifactsByDateRange(RepositorySession session, List<ArtifactMetadata> artifacts, String repoId, String ns, ZonedDateTime startTime,
                                     ZonedDateTime endTime)
        throws MetadataRepositoryException {
    try {
        for (String namespace : this.getChildNamespaces(session, repoId, ns)) {
            getArtifactsByDateRange(session, artifacts, repoId, ns + "." + namespace, startTime, endTime);
        }

        for (String project : getProjects(session, repoId, ns)) {
            for (String version : getProjectVersions(session, repoId, ns, project)) {
                for (ArtifactMetadata artifact : getArtifacts(session, repoId, ns, project, version)) {
                    if (startTime == null || startTime.isBefore(ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())))) {
                        if (endTime == null || endTime.isAfter(ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())))) {
                            artifacts.add(artifact);
                        }
                    }
                }
            }
        }
    } catch (MetadataResolutionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
 
Example 4
Source File: DeploymentServiceImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
@ValidateParams
public void delete(@ValidateStringParam(name = "site") String site, List<String> paths,
                   @ValidateStringParam(name = "approver") String approver, ZonedDateTime scheduledDate)
        throws DeploymentException, SiteNotFoundException {
    if (scheduledDate != null && scheduledDate.isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
        objectStateService.transitionBulk(site, paths, DELETE, NEW_DELETED);

    }
    Set<String> environments = getAllPublishedEnvironments(site);
    for (String environment : environments) {
        List<PublishRequest> items = createDeleteItems(site, environment, paths, approver, scheduledDate);
        for (PublishRequest item : items) {
            publishRequestMapper.insertItemForDeployment(item);
        }
    }
    objectStateService.setSystemProcessingBulk(site, paths, false);
    String statusMessage = studioConfiguration
            .getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_QUEUED);
    try {
        siteService.updatePublishingStatusMessage(site, statusMessage);
    } catch (SiteNotFoundException e) {
        logger.error("Error updating publishing status for site " + site);
    }
}
 
Example 5
Source File: FHIRPathAbstractTemporalValue.java    From FHIR with Apache License 2.0 5 votes vote down vote up
protected int compareTo(ZonedDateTime left, ZonedDateTime right) {
    if (left.isBefore(right)) {
        return -1;
    } else if (left.isAfter(right)) {
        return 1;
    }
    return 0;
}
 
Example 6
Source File: VertexMaxNeighbourDatetimeAttributeBin.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void setKey(GraphReadMethods graph, int attribute, int element) {
    ZonedDateTime currentMax = MIN_DATE_TIME;
    final int transactionCount = graph.getVertexNeighbourCount(element);
    for (int t = 0; t < transactionCount; t++) {
        final int transaction = graph.getVertexNeighbour(element, t);
        final ZonedDateTime zdt = graph.getObjectValue(attribute, transaction);
        if (zdt.isAfter(currentMax)) {
            currentMax = zdt;
        }
    }
    key = currentMax.equals(MIN_DATE_TIME) ? null : currentMax;
}
 
Example 7
Source File: LinkMaxTransactionDatetimeAttributeBin.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void setKey(GraphReadMethods graph, int attribute, int element) {
    ZonedDateTime currentMax = MIN_DATE_TIME;
    final int transactionCount = graph.getLinkTransactionCount(element);
    for (int t = 0; t < transactionCount; t++) {
        final int transaction = graph.getLinkTransaction(element, t);
        final ZonedDateTime zdt = graph.getObjectValue(attribute, transaction);
        if (zdt.isAfter(currentMax)) {
            currentMax = zdt;
        }
    }
    key = currentMax.equals(MIN_DATE_TIME) ? null : currentMax;
}
 
Example 8
Source File: ClientSideRequestStatistics.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public void recordResponse(RxDocumentServiceRequest request, StoreResult storeResult) {
    ZonedDateTime responseTime = ZonedDateTime.now(ZoneOffset.UTC);

    StoreResponseStatistics storeResponseStatistics = new StoreResponseStatistics();
    storeResponseStatistics.requestResponseTime = responseTime;
    storeResponseStatistics.storeResult = storeResult;
    storeResponseStatistics.requestOperationType = request.getOperationType();
    storeResponseStatistics.requestResourceType = request.getResourceType();

    URI locationEndPoint = null;
    if (request.requestContext.locationEndpointToRoute != null) {
        try {
            locationEndPoint = request.requestContext.locationEndpointToRoute.toURI();
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }

    synchronized (this) {
        if (responseTime.isAfter(this.requestEndTime)) {
            this.requestEndTime = responseTime;
        }

        if (locationEndPoint != null) {
            this.regionsContacted.add(locationEndPoint);
        }

        if (storeResponseStatistics.requestOperationType == OperationType.Head ||
                storeResponseStatistics.requestOperationType == OperationType.HeadFeed) {
            this.supplementalResponseStatisticsList.add(storeResponseStatistics);
        } else {
            this.responseStatisticsList.add(storeResponseStatistics);
        }
    }
}
 
Example 9
Source File: WalkForward.java    From ta4j-origins with MIT License 5 votes vote down vote up
/**
 * Builds a list of split indexes from splitDuration.
 * @param series the time series to get split begin indexes of
 * @param splitDuration the duration between 2 splits
 * @return a list of begin indexes after split
 */
public static List<Integer> getSplitBeginIndexes(TimeSeries series, Duration splitDuration) {
    ArrayList<Integer> beginIndexes = new ArrayList<>();

    int beginIndex = series.getBeginIndex();
    int endIndex = series.getEndIndex();
    
    // Adding the first begin index
    beginIndexes.add(beginIndex);

    // Building the first interval before next split
    ZonedDateTime beginInterval = series.getFirstTick().getEndTime();
    ZonedDateTime endInterval = beginInterval.plus(splitDuration);

    for (int i = beginIndex; i <= endIndex; i++) {
        // For each tick...
        ZonedDateTime tickTime = series.getTick(i).getEndTime();
        if (tickTime.isBefore(beginInterval) || !tickTime.isBefore(endInterval)) {
            // Tick out of the interval
            if (!endInterval.isAfter(tickTime)) {
                // Tick after the interval
                // --> Adding a new begin index
                beginIndexes.add(i);
            }

            // Building the new interval before next split
            beginInterval = endInterval.isBefore(tickTime) ? tickTime : endInterval;
            endInterval = beginInterval.plus(splitDuration);
        }
    }
    return beginIndexes;
}
 
Example 10
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}
 
Example 11
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}
 
Example 12
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}
 
Example 13
Source File: UidsCookie.java    From prebid-server-java with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if UID expires date in future otherwise false
 */
private static boolean isLive(UidWithExpiry uid) {
    final ZonedDateTime expires = uid.getExpires();
    return expires != null && expires.isAfter(ZonedDateTime.now());
}
 
Example 14
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}
 
Example 15
Source File: CronExpression.java    From cron with Apache License 2.0 4 votes vote down vote up
private static void checkIfDateTimeBarrierIsReached(ZonedDateTime nextTime, ZonedDateTime dateTimeBarrier) {
    if (nextTime.isAfter(dateTimeBarrier)) {
        throw new IllegalArgumentException("No next execution time could be determined that is before the limit of " + dateTimeBarrier);
    }
}
 
Example 16
Source File: ProcessorListener.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public boolean shouldResync(ZonedDateTime now) {
  return this.resyncPeriodInMillis != 0 && (now.isAfter(this.nextResync) || now.equals(this.nextResync));
}
 
Example 17
Source File: OAuthPublicKeyInMemoryRepository.java    From edison-microservice with Apache License 2.0 4 votes vote down vote up
private boolean isValid(final OAuthPublicKey publicKey) {
    final ZonedDateTime now = ZonedDateTime.now();

    return now.isAfter(publicKey.getValidFrom()) &&
            (Objects.isNull(publicKey.getValidUntil()) || now.isBefore(publicKey.getValidUntil()));
}
 
Example 18
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}
 
Example 19
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}
 
Example 20
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_isAfter_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.isAfter(null);
}