/** * Checks if this date-time is equal to another date-time. * <p> * The comparison is based on the offset date-time and the zone. * To compare for the same instant on the time-line, use {@link #compareTo}. * Only objects of type {@code ChronoZoneDateTime} are compared, other types return false. * * @param obj the object to check, null returns false * @return true if this is equal to the other date-time */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ChronoZonedDateTime) { return compareTo((ChronoZonedDateTime<?>) obj) == 0; } return false; }
/** * Compares two time intervals using the start and end times as primary * and secondary keys, respectively. * * @see java.util.Comparator#compare(Object, Object) */ @Override public int compare(Interval<ChronoZonedDateTime<?>> o1, Interval<ChronoZonedDateTime<?>> o2) { int value = o1.getLower().compareTo(o2.getLower()); if (0 == value) { value = o1.getUpper().compareTo(o2.getUpper()); } return value; } };
@Override public boolean isValid(ChronoZonedDateTime<?> value, ConstraintValidatorContext context) { // null values are valid if ( value == null ) { return true; } TimeProvider timeProvider = context.unwrap( HibernateConstraintValidatorContext.class ) .getTimeProvider(); ZonedDateTime reference = ZonedDateTime.ofInstant( Instant.ofEpochMilli( timeProvider.getCurrentTime() ), value.getZone() ); return value.compareTo( reference ) > 0; } }
@Override public boolean isValid(ChronoZonedDateTime<?> value, ConstraintValidatorContext context) { // null values are valid if ( value == null ) { return true; } TimeProvider timeProvider = context.unwrap( HibernateConstraintValidatorContext.class ) .getTimeProvider(); ZonedDateTime reference = ZonedDateTime.ofInstant( Instant.ofEpochMilli( timeProvider.getCurrentTime() ), value.getZone() ); return value.compareTo( reference ) < 0; } }
return dateOne.compareTo(dateTwo);