86 * {@code ChronoLocalDateTime} is an immutable date-time object that represents a date-time, often
87 * viewed as year-month-day-hour-minute-second. This object can also access other
88 * fields such as day-of-year, day-of-week and week-of-year.
89 * <p>
90 * This class stores all date and time fields, to a precision of nanoseconds.
91 * It does not store or represent a time-zone. For example, the value
92 * "2nd October 2007 at 13:45.30.123456789" can be stored in an {@code ChronoLocalDateTime}.
93 *
94 * @implSpec
95 * This class is immutable and thread-safe.
96 * @serial
97 * @param <D> the concrete type for the date of this date-time
98 * @since 1.8
99 */
100 final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
101 implements ChronoLocalDateTime<D>, Temporal, TemporalAdjuster, Serializable {
102
103 /**
104 * Serialization version.
105 */
106 private static final long serialVersionUID = 4556003607393004514L;
107 /**
108 * Hours per day.
109 */
110 static final int HOURS_PER_DAY = 24;
111 /**
112 * Minutes per hour.
113 */
114 static final int MINUTES_PER_HOUR = 60;
115 /**
116 * Minutes per day.
117 */
118 static final int MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY;
119 /**
120 * Seconds per minute.
121 */
122 static final int SECONDS_PER_MINUTE = 60;
123 /**
124 * Seconds per hour.
125 */
392 }
393 return date.until(endDate, unit);
394 }
395 Objects.requireNonNull(unit, "unit");
396 return unit.between(this, end);
397 }
398
399 //-----------------------------------------------------------------------
400 /**
401 * Writes the ChronoLocalDateTime using a
402 * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
403 * @serialData
404 * <pre>
405 * out.writeByte(2); // identifies a ChronoLocalDateTime
406 * out.writeObject(toLocalDate());
407 * out.witeObject(toLocalTime());
408 * </pre>
409 *
410 * @return the instance of {@code Ser}, not null
411 */
412 private Object writeReplace() {
413 return new Ser(Ser.CHRONO_LOCAL_DATE_TIME_TYPE, this);
414 }
415
416 /**
417 * Defend against malicious streams.
418 *
419 * @param s the stream to read
420 * @throws InvalidObjectException always
421 */
422 private void readObject(ObjectInputStream s) throws InvalidObjectException {
423 throw new InvalidObjectException("Deserialization via serialization delegate");
424 }
425
426 void writeExternal(ObjectOutput out) throws IOException {
427 out.writeObject(date);
428 out.writeObject(time);
429 }
430
431 static ChronoLocalDateTime<?> readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
432 ChronoLocalDate date = (ChronoLocalDate) in.readObject();
433 LocalTime time = (LocalTime) in.readObject();
434 return date.atTime(time);
435 }
436
437 //-----------------------------------------------------------------------
438 @Override
439 public boolean equals(Object obj) {
440 if (this == obj) {
441 return true;
|
86 * {@code ChronoLocalDateTime} is an immutable date-time object that represents a date-time, often
87 * viewed as year-month-day-hour-minute-second. This object can also access other
88 * fields such as day-of-year, day-of-week and week-of-year.
89 * <p>
90 * This class stores all date and time fields, to a precision of nanoseconds.
91 * It does not store or represent a time-zone. For example, the value
92 * "2nd October 2007 at 13:45.30.123456789" can be stored in an {@code ChronoLocalDateTime}.
93 *
94 * @implSpec
95 * This class is immutable and thread-safe.
96 * @serial
97 * @param <D> the concrete type for the date of this date-time
98 * @since 1.8
99 */
100 final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
101 implements ChronoLocalDateTime<D>, Temporal, TemporalAdjuster, Serializable {
102
103 /**
104 * Serialization version.
105 */
106 @java.io.Serial
107 private static final long serialVersionUID = 4556003607393004514L;
108 /**
109 * Hours per day.
110 */
111 static final int HOURS_PER_DAY = 24;
112 /**
113 * Minutes per hour.
114 */
115 static final int MINUTES_PER_HOUR = 60;
116 /**
117 * Minutes per day.
118 */
119 static final int MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY;
120 /**
121 * Seconds per minute.
122 */
123 static final int SECONDS_PER_MINUTE = 60;
124 /**
125 * Seconds per hour.
126 */
393 }
394 return date.until(endDate, unit);
395 }
396 Objects.requireNonNull(unit, "unit");
397 return unit.between(this, end);
398 }
399
400 //-----------------------------------------------------------------------
401 /**
402 * Writes the ChronoLocalDateTime using a
403 * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
404 * @serialData
405 * <pre>
406 * out.writeByte(2); // identifies a ChronoLocalDateTime
407 * out.writeObject(toLocalDate());
408 * out.witeObject(toLocalTime());
409 * </pre>
410 *
411 * @return the instance of {@code Ser}, not null
412 */
413 @java.io.Serial
414 private Object writeReplace() {
415 return new Ser(Ser.CHRONO_LOCAL_DATE_TIME_TYPE, this);
416 }
417
418 /**
419 * Defend against malicious streams.
420 *
421 * @param s the stream to read
422 * @throws InvalidObjectException always
423 */
424 @java.io.Serial
425 private void readObject(ObjectInputStream s) throws InvalidObjectException {
426 throw new InvalidObjectException("Deserialization via serialization delegate");
427 }
428
429 void writeExternal(ObjectOutput out) throws IOException {
430 out.writeObject(date);
431 out.writeObject(time);
432 }
433
434 static ChronoLocalDateTime<?> readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
435 ChronoLocalDate date = (ChronoLocalDate) in.readObject();
436 LocalTime time = (LocalTime) in.readObject();
437 return date.atTime(time);
438 }
439
440 //-----------------------------------------------------------------------
441 @Override
442 public boolean equals(Object obj) {
443 if (this == obj) {
444 return true;
|