@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; } }
/** * Outputs this date-time as a {@code String}. * <p> * The output will include the full zoned date-time and the chronology ID. * * @return a string representation of this date-time, not null */ @Override public String toString() { String str = toLocalDateTime().toString() + getOffset().toString(); if (getOffset() != getZone()) { str += '[' + getZone().toString() + ']'; } return str; }
/** * A hash code for this date-time. * * @return a suitable hash code */ @Override public int hashCode() { return toLocalDateTime().hashCode() ^ getOffset().hashCode() ^ Integer.rotateLeft(getZone().hashCode(), 3); }
/** * Compares this date-time to another date-time, including the chronology. * <p> * The comparison is based first on the instant, then on the local date-time, * then on the zone ID, then on the chronology. * It is "consistent with equals", as defined by {@link Comparable}. * <p> * If all the date-time objects being compared are in the same chronology, then the * additional chronology stage is not required. * * @param other the other date-time to compare to, not null * @return the comparator value, negative if less, positive if greater */ @Override public int compareTo(ChronoZonedDateTime<?> other) { int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); if (cmp == 0) { cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); if (cmp == 0) { cmp = toLocalDateTime().compareTo(other.toLocalDateTime()); if (cmp == 0) { cmp = getZone().getId().compareTo(other.getZone().getId()); if (cmp == 0) { cmp = toLocalDate().getChronology().compareTo(other.toLocalDate().getChronology()); } } } } return cmp; }
@SuppressWarnings("unchecked") @Override public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) { return (R) getZone(); } else if (query == TemporalQueries.chronology()) { return (R) toLocalDate().getChronology(); } else if (query == TemporalQueries.precision()) { return (R) NANOS; } else if (query == TemporalQueries.offset()) { return (R) getOffset(); } else if (query == TemporalQueries.localDate()) { return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay()); } else if (query == TemporalQueries.localTime()) { return (R) toLocalTime(); } return super.query(query); }