java.time.OffsetDateTime.isAfter()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中java.time.OffsetDateTime.isAfter()方法的一些代码示例,展示了OffsetDateTime.isAfter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.isAfter()方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:isAfter

OffsetDateTime.isAfter介绍

[英]Checks if the instant of this date-time is after that of the specified date-time.

This method differs from the comparison in #compareTo and #equals in that it only compares the instant of the date-time. This is equivalent to using dateTime1.toInstant().isAfter(dateTime2.toInstant());.
[中]检查此日期时间的瞬间是否在指定日期时间的瞬间之后。
这种方法不同于#compareTo和#equals中的比较,因为它只比较日期和时间的瞬间。这相当于使用dateTime1。toInstant()。isAfter(dateTime2.toInstant());。

代码示例

代码示例来源:origin: prontera/spring-cloud-rest-tcc

  1. private OffsetDateTime fetchTheRecentlyExpireTime(List<Participant> participantLink) {
  2. Preconditions.checkNotNull(participantLink);
  3. // 计算出过期时间集合
  4. final List<OffsetDateTime> dateTimeList = participantLink.stream()
  5. .flatMap(x -> Stream.of(x.getExpireTime()))
  6. .filter(x -> x.isAfter(OffsetDateTime.now()))
  7. .sorted()
  8. .collect(Collectors.toList());
  9. // 检查是否具有已经过期的事务
  10. if (dateTimeList.size() != participantLink.size()) {
  11. throw new ReservationExpireException("there has a expired transaction");
  12. }
  13. // 检测是否将近过期, 集合经过Validator检查必有一个元素
  14. return dateTimeList.get(0);
  15. }

代码示例来源:origin: org.postgresql/postgresql

  1. public synchronized String toString(OffsetDateTime offsetDateTime) {
  2. if (offsetDateTime.isAfter(MAX_OFFSET_DATETIME)) {
  3. return "infinity";
  4. } else if (OffsetDateTime.MIN.equals(offsetDateTime)) {
  5. return "-infinity";
  6. }
  7. sbuf.setLength(0);
  8. int nano = offsetDateTime.getNano();
  9. if (nanosExceed499(nano)) {
  10. // Technically speaking this is not a proper rounding, however
  11. // it relies on the fact that appendTime just truncates 000..999 nanosecond part
  12. offsetDateTime = offsetDateTime.plus(ONE_MICROSECOND);
  13. }
  14. LocalDateTime localDateTime = offsetDateTime.toLocalDateTime();
  15. LocalDate localDate = localDateTime.toLocalDate();
  16. appendDate(sbuf, localDate);
  17. sbuf.append(' ');
  18. appendTime(sbuf, localDateTime.toLocalTime());
  19. appendTimeZone(sbuf, offsetDateTime.getOffset());
  20. appendEra(sbuf, localDate);
  21. return sbuf.toString();
  22. }

代码示例来源:origin: org.assertj/assertj-core

  1. /**
  2. * Verifies that the actual {@code OffsetDateTime} is <b>strictly</b> after the given one.
  3. * <p>
  4. * Example :
  5. * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z"));</code></pre>
  6. *
  7. * @param other the given {@link java.time.OffsetDateTime}.
  8. * @return this assertion object.
  9. * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
  10. * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
  11. * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the given one.
  12. */
  13. public SELF isAfter(OffsetDateTime other) {
  14. Objects.instance().assertNotNull(info, actual);
  15. assertOffsetDateTimeParameterIsNotNull(other);
  16. if (!actual.isAfter(other)) {
  17. throw Failures.instance().failure(info, shouldBeAfter(actual, other));
  18. }
  19. return myself;
  20. }

代码示例来源:origin: org.assertj/assertj-core

  1. /**
  2. * Verifies that the actual {@code OffsetDateTime} is before or equals to the given one.
  3. * <p>
  4. * Example :
  5. * <pre><code class='java'> assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59Z"))
  6. * .isBeforeOrEqualTo(parse("2000-01-02T00:00:00Z"));</code></pre>
  7. *
  8. * @param other the given {@link java.time.OffsetDateTime}.
  9. * @return this assertion object.
  10. * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
  11. * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
  12. * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the given one.
  13. */
  14. public SELF isBeforeOrEqualTo(OffsetDateTime other) {
  15. Objects.instance().assertNotNull(info, actual);
  16. assertOffsetDateTimeParameterIsNotNull(other);
  17. if (actual.isAfter(other)) {
  18. throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));
  19. }
  20. return myself;
  21. }

代码示例来源:origin: joel-costigliola/assertj-core

  1. /**
  2. * Verifies that the actual {@code OffsetDateTime} is <b>strictly</b> after the given one.
  3. * <p>
  4. * Example :
  5. * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z"));</code></pre>
  6. *
  7. * @param other the given {@link java.time.OffsetDateTime}.
  8. * @return this assertion object.
  9. * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
  10. * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
  11. * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the given one.
  12. */
  13. public SELF isAfter(OffsetDateTime other) {
  14. Objects.instance().assertNotNull(info, actual);
  15. assertOffsetDateTimeParameterIsNotNull(other);
  16. if (!actual.isAfter(other)) {
  17. throw Failures.instance().failure(info, shouldBeAfter(actual, other));
  18. }
  19. return myself;
  20. }

代码示例来源:origin: joel-costigliola/assertj-core

  1. /**
  2. * Verifies that the actual {@code OffsetDateTime} is before or equals to the given one.
  3. * <p>
  4. * Example :
  5. * <pre><code class='java'> assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59Z"))
  6. * .isBeforeOrEqualTo(parse("2000-01-02T00:00:00Z"));</code></pre>
  7. *
  8. * @param other the given {@link java.time.OffsetDateTime}.
  9. * @return this assertion object.
  10. * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
  11. * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
  12. * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the given one.
  13. */
  14. public SELF isBeforeOrEqualTo(OffsetDateTime other) {
  15. Objects.instance().assertNotNull(info, actual);
  16. assertOffsetDateTimeParameterIsNotNull(other);
  17. if (actual.isAfter(other)) {
  18. throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));
  19. }
  20. return myself;
  21. }

代码示例来源:origin: stackoverflow.com

  1. public class Scratch {
  2. public static void main(String... args) throws Exception {
  3. final OffsetDateTime odtMinusSeven = OffsetDateTime.of(2016, 01, 01, 8, 30, 0, 0, ZoneOffset.ofHours(-7));
  4. final OffsetDateTime odtMinusSix = OffsetDateTime.of(2016, 01, 01, 8, 30, 0, 0, ZoneOffset.ofHours(-6));
  5. System.out.println(odtMinusSeven.isAfter(odtMinusSix));
  6. // true
  7. }
  8. }

代码示例来源:origin: Silverpeas/Silverpeas-Core

  1. private static void checkPeriod(final OffsetDateTime startDateTime,
  2. final OffsetDateTime endDateTime) {
  3. Objects.requireNonNull(startDateTime);
  4. Objects.requireNonNull(endDateTime);
  5. if (startDateTime.isAfter(endDateTime) || startDateTime.isEqual(endDateTime)) {
  6. throw new IllegalArgumentException("The end datetime must be after the start datetime");
  7. }
  8. }

代码示例来源:origin: de.adorsys.psd2/consent-management-lib

  1. public boolean isNotExpired() {
  2. return redirectUrlExpirationTimestamp.isAfter(OffsetDateTime.now());
  3. }
  4. }

代码示例来源:origin: kiegroup/optaweb-employee-rostering

  1. public static boolean doTimeslotsIntersect(OffsetDateTime start1, OffsetDateTime end1, OffsetDateTime start2, OffsetDateTime end2) {
  2. return !start1.isAfter(end2) && !end1.isBefore(start2);
  3. }

代码示例来源:origin: adorsys/xs2a

  1. public boolean isNotExpired() {
  2. return redirectUrlExpirationTimestamp.isAfter(OffsetDateTime.now());
  3. }
  4. }

代码示例来源:origin: PacktPublishing/OAuth-2.0-Cookbook

  1. public boolean hasExpired() {
  2. OffsetDateTime expirationDateTime = OffsetDateTime.ofInstant(
  3. Instant.ofEpochSecond(expirationTime), ZoneId.systemDefault());
  4. OffsetDateTime now = OffsetDateTime.now(ZoneId.systemDefault());
  5. return now.isAfter(expirationDateTime);
  6. }

代码示例来源:origin: PacktPublishing/OAuth-2.0-Cookbook

  1. public boolean hasExpired() {
  2. OffsetDateTime expirationDateTime = OffsetDateTime.ofInstant(
  3. Instant.ofEpochSecond(expirationTime), ZoneId.systemDefault());
  4. OffsetDateTime now = OffsetDateTime.now(ZoneId.systemDefault());
  5. return now.isAfter(expirationDateTime);
  6. }

代码示例来源:origin: PacktPublishing/OAuth-2.0-Cookbook

  1. public boolean hasExpired() {
  2. OffsetDateTime expirationDateTime = OffsetDateTime.ofInstant(
  3. Instant.ofEpochSecond(expirationTime), ZoneId.systemDefault());
  4. OffsetDateTime now = OffsetDateTime.now(ZoneId.systemDefault());
  5. return now.isAfter(expirationDateTime);
  6. }

代码示例来源:origin: com.github.robozonky/robozonky-notifications

  1. private Stream<OffsetDateTime> filterValidTimestamps(final Set<OffsetDateTime> timestamps) {
  2. final OffsetDateTime now = DateUtil.offsetNow();
  3. return timestamps.stream().filter(timestamp -> timestamp.plus(period).isAfter(now));
  4. }

代码示例来源:origin: RoboZonky/robozonky

  1. private Stream<OffsetDateTime> filterValidTimestamps(final Set<OffsetDateTime> timestamps) {
  2. final OffsetDateTime now = DateUtil.offsetNow();
  3. return timestamps.stream().filter(timestamp -> timestamp.plus(period).isAfter(now));
  4. }

代码示例来源:origin: rocks.xmpp/xmpp-extensions-common

  1. /**
  2. * Creates a headers element with a time period.
  3. *
  4. * @param start The start date.
  5. * @param stop The stop date.
  6. * @return The header.
  7. * @see <a href="https://xmpp.org/extensions/xep-0149.html">XEP-0149: Time Periods</a>
  8. */
  9. public static Headers ofTimePeriod(OffsetDateTime start, OffsetDateTime stop) {
  10. // If both a start time and a stop time are specified, the stop time MUST be later than the start time.
  11. if (start.isAfter(stop)) {
  12. throw new IllegalArgumentException("start date must not be after the start date.");
  13. }
  14. return of(Header.ofStartDate(start), Header.ofStopDate(stop));
  15. }

代码示例来源:origin: RoboZonky/robozonky

  1. private Either<InvestmentFailure, BigDecimal> investOrDelegateOnCaptcha(final RecommendedLoan r) {
  2. final Optional<OffsetDateTime> captchaEndDateTime =
  3. r.descriptor().getLoanCaptchaProtectionEndDateTime();
  4. final boolean isCaptchaProtected = captchaEndDateTime.isPresent() &&
  5. captchaEndDateTime.get().isAfter(DateUtil.offsetNow());
  6. final boolean confirmationSupported = this.provider != null;
  7. if (!isCaptchaProtected) {
  8. return this.investLocallyFailingOnCaptcha(r);
  9. } else if (confirmationSupported) {
  10. return this.delegateOrReject(r);
  11. }
  12. LOGGER.warn("CAPTCHA protected, no support for delegation. Not investing: {}.", r);
  13. return Either.left(InvestmentFailure.REJECTED);
  14. }

代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene

  1. private OffsetDateTime next(OffsetDateTime from, boolean forward) {
  2. OffsetDateTime to;
  3. if (forward) {
  4. to = this._intervalDate == null ? from : from.plus(this._intervalDate);
  5. to = this._intervalTime == null ? to : to.plus(this._intervalTime);
  6. if (this._end != null && to.isAfter(this._end)) to = this._end;
  7. } else {
  8. to = this._intervalDate == null ? from : from.minus(this._intervalDate);
  9. to = this._intervalTime == null ? to : to.minus(this._intervalTime);
  10. if (this._end != null && to.isBefore(this._start)) to = this._start;
  11. }
  12. return to;
  13. }

代码示例来源:origin: net.aholbrook.paseto/core

  1. @Override
  2. public void check(Token token, VerificationContext context) {
  3. OffsetDateTime time = this.time == null ? OffsetDateTime.now(Clock.systemUTC()) : this.time;
  4. if (token.getIssuedAt() == null) {
  5. throw new MissingClaimException(Token.CLAIM_ISSUED_AT, NAME, token);
  6. }
  7. if (token.getIssuedAt().minus(allowableDrift).isAfter(time)) {
  8. throw new IssuedInFutureException(time, token.getIssuedAt(), NAME, token);
  9. }
  10. }
  11. }

相关文章