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

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

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

OffsetDateTime.compareTo介绍

[英]Compares this OffsetDateTime to another date-time.

The comparison is based on the instant then on the local date-time. It is "consistent with equals", as defined by Comparable.

For example, the following is the comparator order:

  1. 2008-12-03T10:30+01:00
  2. 2008-12-03T11:00+01:00
  3. 2008-12-03T12:00+02:00
  4. 2008-12-03T11:30+01:00
  5. 2008-12-03T12:00+01:00
  6. 2008-12-03T12:30+01:00
    Values #2 and #3 represent the same instant on the time-line. When two values represent the same instant, the local date-time is compared to distinguish them. This step is needed to make the ordering consistent with equals().
    [中]将此OffsetDateTime与另一个日期时间进行比较。
    比较是基于瞬间,然后是本地日期时间。它是“与平等相一致的”,正如Comparable所定义的那样。
    例如,以下是比较器顺序:
    1.2008-12-03T10:30+01:00
    1.2008-12-03T11:00+01:00
    1.2008-12-03T12:00+02:00
    1.2008-12-03T11:30+01:00
    1.2008-12-03T12:00+01:00
    1.2008-12-03T12:30+01:00
    值#2和#3表示时间线上的同一时刻。当两个值代表同一时刻时,将比较本地日期时间以区分它们。要使排序与equals()一致,需要执行此步骤。

代码示例

代码示例来源:origin: DV8FromTheWorld/JDA

  1. @Override
  2. public int compareTo(Role r)
  3. {
  4. if (this == r)
  5. return 0;
  6. if (!this.getGuild().equals(r.getGuild()))
  7. throw new IllegalArgumentException("Cannot compare roles that aren't from the same guild!");
  8. if (this.getPositionRaw() != r.getPositionRaw())
  9. return this.getPositionRaw() - r.getPositionRaw();
  10. OffsetDateTime thisTime = this.getCreationTime();
  11. OffsetDateTime rTime = r.getCreationTime();
  12. //We compare the provided role's time to this's time instead of the reverse as one would expect due to how
  13. // discord deals with hierarchy. The more recent a role was created, the lower its hierarchy ranking when
  14. // it shares the same position as another role.
  15. return rTime.compareTo(thisTime);
  16. }

代码示例来源:origin: pholser/junit-quickcheck

  1. /**
  2. * <p>Tells this generator to produce values within a specified
  3. * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max()
  4. * maximum}, inclusive, with uniform distribution, down to the
  5. * nanosecond.</p>
  6. *
  7. * <p>If an endpoint of the range is not specified, the generator will use
  8. * dates with values of either {@link OffsetDateTime#MIN} or
  9. * {@link OffsetDateTime#MAX} as appropriate.</p>
  10. *
  11. * <p>{@link InRange#format()} describes
  12. * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to
  13. * interpret the range's endpoints}.</p>
  14. *
  15. * @param range annotation that gives the range's constraints
  16. */
  17. public void configure(InRange range) {
  18. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(range.format());
  19. if (!defaultValueOf(InRange.class, "min").equals(range.min()))
  20. min = OffsetDateTime.parse(range.min(), formatter);
  21. if (!defaultValueOf(InRange.class, "max").equals(range.max()))
  22. max = OffsetDateTime.parse(range.max(), formatter);
  23. if (min.compareTo(max) > 0)
  24. throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max()));
  25. }

代码示例来源:origin: com.sqlapp/sqlapp-core

  1. @Override
  2. public boolean hasNext() {
  3. if (this.step>0){
  4. return (next.compareTo(end)<0);
  5. } else{
  6. return (next.compareTo(end)>0);
  7. }
  8. }

代码示例来源:origin: org.jadira.usertype/usertype.core

  1. @Override
  2. public int compare(Object o1, Object o2) {
  3. return ((OffsetDateTime) o1).compareTo((OffsetDateTime) o2);
  4. }
  5. }

代码示例来源:origin: org.jadira.usertype/usertype.extended

  1. @Override
  2. public int compare(Object o1, Object o2) {
  3. return ((OffsetDateTime) o1).compareTo((OffsetDateTime) o2);
  4. }
  5. }

代码示例来源:origin: org.jadira.usertype/usertype.core

  1. @Override
  2. public int compare(Object o1, Object o2) {
  3. return ((OffsetDateTime) o1).compareTo((OffsetDateTime) o2);
  4. }

代码示例来源:origin: signaflo/java-timeseries

  1. @Override
  2. public int compareTo(@NonNull Time otherTime) {
  3. return this.dateTime.compareTo(otherTime.dateTime);
  4. }

代码示例来源:origin: MER-C/wiki-java

  1. /**
  2. * Compares this event to another one based on the recentness of their
  3. * timestamps (more recent = positive return value), then
  4. * alphabetically by user.
  5. * @param other the event to compare to
  6. * @return the comparator value, negative if less, positive if greater
  7. */
  8. @Override
  9. public int compareTo(Wiki.Event other)
  10. {
  11. int result = timestamp.compareTo(other.timestamp);
  12. if (result == 0 && user != null)
  13. result = user.compareTo(other.user);
  14. return result;
  15. }
  16. }

代码示例来源:origin: com.sqlapp/sqlapp-core

  1. @Override
  2. public boolean hasNext() {
  3. if (this.step.isPositive()){
  4. return (next.compareTo(end)<0);
  5. } else{
  6. return (next.compareTo(end)>0);
  7. }
  8. }

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

  1. /**
  2. * Is this period includes the specified temporal?
  3. * @param dateTime either a date or a date time. Any other temporal type isn't supported.
  4. * @return true if the specified date is included in this period, false otherwise.
  5. */
  6. public boolean includes(final Temporal dateTime) {
  7. OffsetDateTime dt = asOffsetDateTime(dateTime);
  8. return dt.compareTo(startDateTime) >= 0 && dt.compareTo(endDateTime) <= 0;
  9. }

代码示例来源:origin: org.n52.wps/engine

  1. private Predicate<Path> shouldBeDeleted(OffsetDateTime threshold) {
  2. return path -> Files.isDirectory(path) && getLastModifiedTime(path).filter(dt -> dt.compareTo(
  3. threshold) <= 0).isPresent();
  4. }

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

  1. /**
  2. * Is this period ends before the specified temporal?
  3. * @param dateTime either a date or a date time. Any other temporal type isn't supported.
  4. * @return true if this period's end date is at or before the specified temporal (the period's
  5. * end date is exclusive).
  6. */
  7. public boolean endsBefore(final Temporal dateTime) {
  8. OffsetDateTime dt = asOffsetDateTime(dateTime);
  9. return dt.compareTo(endDateTime) >= 0;
  10. }

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

  1. /**
  2. * Is this period starts after the specified temporal?
  3. * @param dateTime either a date or a date time. Any other temporal type isn't supported.
  4. * @return true if this period's start date is after the specified temporal (the period's
  5. * start date is inclusive).
  6. */
  7. public boolean startsAfter(final Temporal dateTime) {
  8. OffsetDateTime dt = asOffsetDateTime(dateTime);
  9. return dt.compareTo(startDateTime) < 0;
  10. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.hibernate-validator

  1. @Override
  2. public boolean isValid(OffsetDateTime value, ConstraintValidatorContext context) {
  3. // null values are valid
  4. if ( value == null ) {
  5. return true;
  6. }
  7. TimeProvider timeProvider = context.unwrap( HibernateConstraintValidatorContext.class )
  8. .getTimeProvider();
  9. OffsetDateTime reference = OffsetDateTime.ofInstant( Instant.ofEpochMilli( timeProvider.getCurrentTime() ), value.getOffset() );
  10. return value.compareTo( reference ) < 0;
  11. }
  12. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.hibernate-validator

  1. @Override
  2. public boolean isValid(OffsetDateTime value, ConstraintValidatorContext context) {
  3. // null values are valid
  4. if ( value == null ) {
  5. return true;
  6. }
  7. TimeProvider timeProvider = context.unwrap( HibernateConstraintValidatorContext.class )
  8. .getTimeProvider();
  9. OffsetDateTime reference = OffsetDateTime.ofInstant( Instant.ofEpochMilli( timeProvider.getCurrentTime() ), value.getOffset() );
  10. return value.compareTo( reference ) > 0;
  11. }
  12. }

代码示例来源:origin: it.ozimov/spring-boot-email-core

  1. private boolean beforeLastLoadedFromPersistenceLayer(final EmailSchedulingData emailSchedulingData) {
  2. if (!hasPersistence || !hasElements()) {
  3. return true;
  4. }
  5. final EmailSchedulingData least = getLeastOfAllLast().get();
  6. final int scheduledDateTimeComparison = emailSchedulingData.getScheduledDateTime().compareTo(least.getScheduledDateTime().plus(queuabilityDelta));
  7. return scheduledDateTimeComparison < 0 || (scheduledDateTimeComparison == 0 && emailSchedulingData.getAssignedPriority() < least.getAssignedPriority());
  8. }

代码示例来源:origin: ozimov/spring-boot-email-tools

  1. private boolean beforeLastLoadedFromPersistenceLayer(final EmailSchedulingData emailSchedulingData) {
  2. if (!hasPersistence || !hasElements()) {
  3. return true;
  4. }
  5. final EmailSchedulingData least = getLeastOfAllLast().get();
  6. final int scheduledDateTimeComparison = emailSchedulingData.getScheduledDateTime().compareTo(least.getScheduledDateTime().plus(queuabilityDelta));
  7. return scheduledDateTimeComparison < 0 || (scheduledDateTimeComparison == 0 && emailSchedulingData.getAssignedPriority() < least.getAssignedPriority());
  8. }

代码示例来源:origin: com.pholser/junit-quickcheck-generators

  1. /**
  2. * <p>Tells this generator to produce values within a specified
  3. * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max()
  4. * maximum}, inclusive, with uniform distribution, down to the
  5. * nanosecond.</p>
  6. *
  7. * <p>If an endpoint of the range is not specified, the generator will use
  8. * dates with values of either {@link OffsetDateTime#MIN} or
  9. * {@link OffsetDateTime#MAX} as appropriate.</p>
  10. *
  11. * <p>{@link InRange#format()} describes
  12. * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to
  13. * interpret the range's endpoints}.</p>
  14. *
  15. * @param range annotation that gives the range's constraints
  16. */
  17. public void configure(InRange range) {
  18. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(range.format());
  19. if (!defaultValueOf(InRange.class, "min").equals(range.min()))
  20. min = OffsetDateTime.parse(range.min(), formatter);
  21. if (!defaultValueOf(InRange.class, "max").equals(range.max()))
  22. max = OffsetDateTime.parse(range.max(), formatter);
  23. if (min.compareTo(max) > 0)
  24. throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max()));
  25. }

代码示例来源:origin: org.openbase.bco/ontology.lib

  1. final OffsetDateTime lastHeartbeat = OffsetDateTime.parse(lastTimeStamp).plusSeconds(OntConfig.HEART_BEAT_TOLERANCE);
  2. if (lastHeartbeat.compareTo(now) >= 0) {

相关文章