/** * Checks if this date-time is equal to another date-time, including the chronology. * <p> * Compares this date-time with another ensuring that the date-time and chronology are the same. * * @param obj the object to check, null returns false * @return true if this is equal to the other date */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ChronoLocalDateTime) { return compareTo((ChronoLocalDateTime<?>) obj) == 0; } return false; }
/** * Compares this date-time to another date-time. * <p> * The comparison is primarily based on the date-time, from earliest to latest. * It is "consistent with equals", as defined by {@link Comparable}. * <p> * If all the date-times being compared are instances of {@code LocalDateTime}, * then the comparison will be entirely based on the date-time. * If some dates being compared are in different chronologies, then the * chronology is also considered, see {@link ChronoLocalDateTime#compareTo}. * * @param other the other date-time to compare to, not null * @return the comparator value, negative if less, positive if greater */ @Override // override for Javadoc and performance public int compareTo(ChronoLocalDateTime<?> other) { if (other instanceof LocalDateTime) { return compareTo0((LocalDateTime) other); } return super.compareTo(other); }
/** * 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; }