/** * Checks if this date is after the specified date ignoring the chronology. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the underlying date and not the chronology. * This allows dates in different calendar systems to be compared based * on the time-line position. * This is equivalent to using {@code date1.toEpochDay() > date2.toEpochDay()}. * * @param other the other date to compare to, not null * @return true if this is after the specified date */ public boolean isAfter(ChronoLocalDate other) { return this.toEpochDay() > other.toEpochDay(); }
/** * Checks if this date is before the specified date ignoring the chronology. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the underlying date and not the chronology. * This allows dates in different calendar systems to be compared based * on the time-line position. * This is equivalent to using {@code date1.toEpochDay() < date2.toEpochDay()}. * * @param other the other date to compare to, not null * @return true if this is before the specified date */ public boolean isBefore(ChronoLocalDate other) { return this.toEpochDay() < other.toEpochDay(); }
/** * Checks if this date is equal to the specified date ignoring the chronology. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the underlying date and not the chronology. * This allows dates in different calendar systems to be compared based * on the time-line position. * This is equivalent to using {@code date1.toEpochDay() == date2.toEpochDay()}. * * @param other the other date to compare to, not null * @return true if the underlying date is equal to the specified date */ public boolean isEqual(ChronoLocalDate other) { return this.toEpochDay() == other.toEpochDay(); }
@Override public int compare(ChronoLocalDate date1, ChronoLocalDate date2) { return Jdk8Methods.compareLongs(date1.toEpochDay(), date2.toEpochDay()); } };
/** * Serializes the {@code LocalDate.toEpochDay} value to * {@code buffer}. * @param o a {@code LocalDate} instance. * @param buffer write to this buffer. * @throws BufferOverflowException * if {@code buffer} does not contain enough space to store * the {@code long} nanoseconds value. */ @Override public void serialize(final Object o, final ByteBuffer buffer) throws BufferOverflowException { if (o instanceof LocalDate) { buffer.putLong(((ChronoLocalDate) o).toEpochDay()); } return; } // end of serialize(Object, ByteBuffer)
@Override public Temporal adjustInto(Temporal temporal) { return temporal.with(EPOCH_DAY, toEpochDay()); }
long daysUntil(ChronoLocalDate end) { return end.toEpochDay() - toEpochDay(); // no overflow }
/** * A hash code for this date. * * @return a suitable hash code */ @Override public int hashCode() { long epDay = toEpochDay(); return getChronology().hashCode() ^ ((int) (epDay ^ (epDay >>> 32))); }
/** * Checks if this date-time is equal to the specified date-time ignoring the chronology. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the underlying date and time and not the chronology. * This allows date-times in different calendar systems to be compared based * on the time-line position. * * @param other the other date-time to compare to, not null * @return true if the underlying date-time is equal to the specified date-time on the timeline */ public boolean isEqual(ChronoLocalDateTime<?> other) { // Do the time check first, it is cheaper than computing EPOCH day. return this.toLocalTime().toNanoOfDay() == other.toLocalTime().toNanoOfDay() && this.toLocalDate().toEpochDay() == other.toLocalDate().toEpochDay(); }
private void resolveMakeChanges(TemporalField targetField, ChronoLocalDate date) { if (chrono.equals(date.getChronology()) == false) { throw new DateTimeException("ChronoLocalDate must use the effective parsed chronology: " + chrono); } long epochDay = date.toEpochDay(); Long old = fieldValues.put(ChronoField.EPOCH_DAY, epochDay); if (old != null && old.longValue() != epochDay) { throw new DateTimeException("Conflict found: " + LocalDate.ofEpochDay(old) + " differs from " + LocalDate.ofEpochDay(epochDay) + " while resolving " + targetField); } }
/** * Checks if this date-time is after the specified date-time ignoring the chronology. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the underlying date-time and not the chronology. * This allows dates in different calendar systems to be compared based * on the time-line position. * * @param other the other date-time to compare to, not null * @return true if this is after the specified date-time */ public boolean isAfter(ChronoLocalDateTime<?> other) { long thisEpDay = this.toLocalDate().toEpochDay(); long otherEpDay = other.toLocalDate().toEpochDay(); return thisEpDay > otherEpDay || (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() > other.toLocalTime().toNanoOfDay()); }
/** * Checks if this date-time is before the specified date-time ignoring the chronology. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the underlying date-time and not the chronology. * This allows dates in different calendar systems to be compared based * on the time-line position. * * @param other the other date-time to compare to, not null * @return true if this is before the specified date-time */ public boolean isBefore(ChronoLocalDateTime<?> other) { long thisEpDay = this.toLocalDate().toEpochDay(); long otherEpDay = other.toLocalDate().toEpochDay(); return thisEpDay < otherEpDay || (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() < other.toLocalTime().toNanoOfDay()); }
@Override public int compare(ChronoLocalDateTime<?> datetime1, ChronoLocalDateTime<?> datetime2) { int cmp = Jdk8Methods.compareLongs(datetime1.toLocalDate().toEpochDay(), datetime2.toLocalDate().toEpochDay()); if (cmp == 0) { cmp = Jdk8Methods.compareLongs(datetime1.toLocalTime().toNanoOfDay(), datetime2.toLocalTime().toNanoOfDay()); } return cmp; } };
@Override public Temporal adjustInto(Temporal temporal) { return temporal .with(EPOCH_DAY, toLocalDate().toEpochDay()) .with(NANO_OF_DAY, toLocalTime().toNanoOfDay()); }
/** * Converts this date-time to the number of seconds from the epoch * of 1970-01-01T00:00:00Z. * <p> * This uses the {@linkplain #toLocalDateTime() local date-time} and * {@linkplain #getOffset() offset} to calculate the epoch-second value, * which is the number of elapsed seconds from 1970-01-01T00:00:00Z. * Instants on the time-line after the epoch are positive, earlier are negative. * * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z */ public long toEpochSecond() { long epochDay = toLocalDate().toEpochDay(); long secs = epochDay * 86400 + toLocalTime().toSecondOfDay(); secs -= getOffset().getTotalSeconds(); return secs; }
/** * Converts this date-time to the number of seconds from the epoch * of 1970-01-01T00:00:00Z. * <p> * This combines this local date-time and the specified offset to calculate the * epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z. * Instants on the time-line after the epoch are positive, earlier are negative. * * @param offset the offset to use for the conversion, not null * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z */ public long toEpochSecond(ZoneOffset offset) { Jdk8Methods.requireNonNull(offset, "offset"); long epochDay = toLocalDate().toEpochDay(); long secs = epochDay * 86400 + toLocalTime().toSecondOfDay(); secs -= offset.getTotalSeconds(); return secs; }
@Override public java.sql.Date convertObject(Object value) { if (isEmpty(value)){ return getDefaultValue(); }else if (value instanceof java.sql.Date){ return new java.sql.Date(((java.sql.Date)value).getTime()); }else if (value instanceof java.util.Date){ return DateUtils.toSqlDate((java.util.Date)value); }else if (value instanceof ChronoLocalDate){ return DateUtils.toSqlDate(((ChronoLocalDate)value).toEpochDay()); }else if (value instanceof LocalDateTime){ return DateUtils.toSqlDate(((LocalDateTime)value).toLocalDate().toEpochDay()); }else if (value instanceof OffsetDateTime){ OffsetDateTime dateTime=OffsetDateTime.class.cast(value); return DateUtils.toSqlDate(dateTime.toLocalDate().toEpochDay()); }else if (value instanceof ZonedDateTime){ ZonedDateTime dateTime=ZonedDateTime.class.cast(value); return DateUtils.toSqlDate(dateTime.toLocalDate().toEpochDay()); }else if (value instanceof Calendar){ return DateUtils.toSqlDate((Calendar)value); }else if (value instanceof Long){ return DateUtils.toSqlDate(((Long)value).longValue()); } ZonedDateTime zonedDateTime= getZonedDateTimeConverter().convertObject(value); return toDate(zonedDateTime); }
@SuppressWarnings("unchecked") @Override public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.chronology()) { return (R) getChronology(); } else if (query == TemporalQueries.precision()) { return (R) ChronoUnit.DAYS; } else if (query == TemporalQueries.localDate()) { return (R) LocalDate.ofEpochDay(toEpochDay()); } else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { return null; } return super.query(query); }
@SuppressWarnings("unchecked") @Override public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.chronology()) { return (R) getChronology(); } else if (query == TemporalQueries.precision()) { return (R) NANOS; } else if (query == TemporalQueries.localDate()) { return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay()); } else if (query == TemporalQueries.localTime()) { return (R) toLocalTime(); } else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { return null; } return super.query(query); }
@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); }