/** * Gets the chronology of this date-time. * <p> * The {@code Chronology} represents the calendar system in use. * The era and other fields in {@link ChronoField} are defined by the chronology. * * @return the chronology, not null */ public Chronology getChronology() { return toLocalDate().getChronology(); }
/** * 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; }
private void mergeInstantFields0(ZoneId selectedZone) { Instant instant = Instant.ofEpochSecond(fieldValues.remove(INSTANT_SECONDS)); ChronoZonedDateTime<?> zdt = chrono.zonedDateTime(instant, selectedZone); if (date == null) { addObject(zdt.toLocalDate()); } else { resolveMakeChanges(INSTANT_SECONDS, zdt.toLocalDate()); } addFieldValue(SECOND_OF_DAY, (long) zdt.toLocalTime().toSecondOfDay()); }
@Override public ChronoZonedDateTime<D> minus(TemporalAmount amount) { return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amount)); }
@Override public ChronoZonedDateTime<D> minus(long amountToSubtract, TemporalUnit unit) { return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amountToSubtract, unit)); }
@Override public abstract ChronoZonedDateTime<D> plus(long amountToAdd, TemporalUnit unit);
@Override public abstract ChronoZonedDateTime<D> with(TemporalField field, long newValue);
/** * 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; }
@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); }