private void write(SerializeWriter out, TemporalAccessor object, String format) { DateTimeFormatter formatter; if ("unixtime".equals(format) && object instanceof ChronoZonedDateTime) { long seconds = ((ChronoZonedDateTime) object).toEpochSecond(); out.writeInt((int) seconds); return; } if (format == formatter_iso8601_pattern) { formatter = formatter_iso8601; } else { formatter = DateTimeFormatter.ofPattern(format); } String text = formatter.format((TemporalAccessor) object); out.writeString(text); } }
private void write(SerializeWriter out, TemporalAccessor object, String format) { DateTimeFormatter formatter; if ("unixtime".equals(format) && object instanceof ChronoZonedDateTime) { long seconds = ((ChronoZonedDateTime) object).toEpochSecond(); out.writeInt((int) seconds); return; } if (format == formatter_iso8601_pattern) { formatter = formatter_iso8601; } else { formatter = DateTimeFormatter.ofPattern(format); } String text = formatter.format((TemporalAccessor) object); out.writeString(text); } }
/** * Converts this date-time to an {@code Instant}. * <p> * This returns an {@code Instant} representing the same point on the * time-line as this date-time. The calculation combines the * {@linkplain #toLocalDateTime() local date-time} and * {@linkplain #getOffset() offset}. * * @return an {@code Instant} representing the same instant, not null */ public Instant toInstant() { return Instant.ofEpochSecond(toEpochSecond(), toLocalTime().getNano()); }
/** * Checks if the instant of this date-time is equal to that of the specified date-time. * <p> * This method differs from the comparison in {@link #compareTo} and {@link #equals} * in that it only compares the instant of the date-time. This is equivalent to using * {@code dateTime1.toInstant().equals(dateTime2.toInstant());}. * * @param other the other date-time to compare to, not null * @return true if the instant equals the instant of the specified date-time */ public boolean isEqual(ChronoZonedDateTime<?> other) { return toEpochSecond() == other.toEpochSecond() && toLocalTime().getNano() == other.toLocalTime().getNano(); }
/** * Checks if the instant of this date-time is before that of the specified date-time. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the instant of the date-time. This is equivalent to using * {@code dateTime1.toInstant().isBefore(dateTime2.toInstant());}. * * @param other the other date-time to compare to, not null * @return true if this point is before the specified date-time */ public boolean isBefore(ChronoZonedDateTime<?> other) { long thisEpochSec = toEpochSecond(); long otherEpochSec = other.toEpochSecond(); return thisEpochSec < otherEpochSec || (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano()); }
/** * Checks if the instant of this date-time is after that of the specified date-time. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the instant of the date-time. This is equivalent to using * {@code dateTime1.toInstant().isAfter(dateTime2.toInstant());}. * * @param other the other date-time to compare to, not null * @return true if this is after the specified date-time */ public boolean isAfter(ChronoZonedDateTime<?> other) { long thisEpochSec = toEpochSecond(); long otherEpochSec = other.toEpochSecond(); return thisEpochSec > otherEpochSec || (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano()); }
@Override public int compare(ChronoZonedDateTime<?> datetime1, ChronoZonedDateTime<?> datetime2) { int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond()); if (cmp == 0) { cmp = Jdk8Methods.compareLongs(datetime1.toLocalTime().toNanoOfDay(), datetime2.toLocalTime().toNanoOfDay()); } return cmp; } };
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return toLocalDateTime().getLong(field); } return field.getFrom(this); }
/** * 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; }