136 implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable {
137
138 /**
139 * The minimum supported {@code LocalDateTime}, '-999999999-01-01T00:00:00'.
140 * This is the local date-time of midnight at the start of the minimum date.
141 * This combines {@link LocalDate#MIN} and {@link LocalTime#MIN}.
142 * This could be used by an application as a "far past" date-time.
143 */
144 public static final LocalDateTime MIN = LocalDateTime.of(LocalDate.MIN, LocalTime.MIN);
145 /**
146 * The maximum supported {@code LocalDateTime}, '+999999999-12-31T23:59:59.999999999'.
147 * This is the local date-time just before midnight at the end of the maximum date.
148 * This combines {@link LocalDate#MAX} and {@link LocalTime#MAX}.
149 * This could be used by an application as a "far future" date-time.
150 */
151 public static final LocalDateTime MAX = LocalDateTime.of(LocalDate.MAX, LocalTime.MAX);
152
153 /**
154 * Serialization version.
155 */
156 private static final long serialVersionUID = 6207766400415563566L;
157
158 /**
159 * The date part.
160 */
161 private final LocalDate date;
162 /**
163 * The time part.
164 */
165 private final LocalTime time;
166
167 //-----------------------------------------------------------------------
168 /**
169 * Obtains the current date-time from the system clock in the default time-zone.
170 * <p>
171 * This will query the {@link Clock#systemDefaultZone() system clock} in the default
172 * time-zone to obtain the current date-time.
173 * <p>
174 * Using this method will prevent the ability to use an alternate clock for testing
175 * because the clock is hard-coded.
1968 * @return a string representation of this date-time, not null
1969 */
1970 @Override
1971 public String toString() {
1972 return date.toString() + 'T' + time.toString();
1973 }
1974
1975 //-----------------------------------------------------------------------
1976 /**
1977 * Writes the object using a
1978 * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1979 * @serialData
1980 * <pre>
1981 * out.writeByte(5); // identifies a LocalDateTime
1982 * // the <a href="{@docRoot}/serialized-form.html#java.time.LocalDate">date</a> excluding the one byte header
1983 * // the <a href="{@docRoot}/serialized-form.html#java.time.LocalTime">time</a> excluding the one byte header
1984 * </pre>
1985 *
1986 * @return the instance of {@code Ser}, not null
1987 */
1988 private Object writeReplace() {
1989 return new Ser(Ser.LOCAL_DATE_TIME_TYPE, this);
1990 }
1991
1992 /**
1993 * Defend against malicious streams.
1994 *
1995 * @param s the stream to read
1996 * @throws InvalidObjectException always
1997 */
1998 private void readObject(ObjectInputStream s) throws InvalidObjectException {
1999 throw new InvalidObjectException("Deserialization via serialization delegate");
2000 }
2001
2002 void writeExternal(DataOutput out) throws IOException {
2003 date.writeExternal(out);
2004 time.writeExternal(out);
2005 }
2006
2007 static LocalDateTime readExternal(DataInput in) throws IOException {
2008 LocalDate date = LocalDate.readExternal(in);
2009 LocalTime time = LocalTime.readExternal(in);
2010 return LocalDateTime.of(date, time);
2011 }
2012
2013 }
|
136 implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable {
137
138 /**
139 * The minimum supported {@code LocalDateTime}, '-999999999-01-01T00:00:00'.
140 * This is the local date-time of midnight at the start of the minimum date.
141 * This combines {@link LocalDate#MIN} and {@link LocalTime#MIN}.
142 * This could be used by an application as a "far past" date-time.
143 */
144 public static final LocalDateTime MIN = LocalDateTime.of(LocalDate.MIN, LocalTime.MIN);
145 /**
146 * The maximum supported {@code LocalDateTime}, '+999999999-12-31T23:59:59.999999999'.
147 * This is the local date-time just before midnight at the end of the maximum date.
148 * This combines {@link LocalDate#MAX} and {@link LocalTime#MAX}.
149 * This could be used by an application as a "far future" date-time.
150 */
151 public static final LocalDateTime MAX = LocalDateTime.of(LocalDate.MAX, LocalTime.MAX);
152
153 /**
154 * Serialization version.
155 */
156 @java.io.Serial
157 private static final long serialVersionUID = 6207766400415563566L;
158
159 /**
160 * The date part.
161 */
162 private final LocalDate date;
163 /**
164 * The time part.
165 */
166 private final LocalTime time;
167
168 //-----------------------------------------------------------------------
169 /**
170 * Obtains the current date-time from the system clock in the default time-zone.
171 * <p>
172 * This will query the {@link Clock#systemDefaultZone() system clock} in the default
173 * time-zone to obtain the current date-time.
174 * <p>
175 * Using this method will prevent the ability to use an alternate clock for testing
176 * because the clock is hard-coded.
1969 * @return a string representation of this date-time, not null
1970 */
1971 @Override
1972 public String toString() {
1973 return date.toString() + 'T' + time.toString();
1974 }
1975
1976 //-----------------------------------------------------------------------
1977 /**
1978 * Writes the object using a
1979 * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1980 * @serialData
1981 * <pre>
1982 * out.writeByte(5); // identifies a LocalDateTime
1983 * // the <a href="{@docRoot}/serialized-form.html#java.time.LocalDate">date</a> excluding the one byte header
1984 * // the <a href="{@docRoot}/serialized-form.html#java.time.LocalTime">time</a> excluding the one byte header
1985 * </pre>
1986 *
1987 * @return the instance of {@code Ser}, not null
1988 */
1989 @java.io.Serial
1990 private Object writeReplace() {
1991 return new Ser(Ser.LOCAL_DATE_TIME_TYPE, this);
1992 }
1993
1994 /**
1995 * Defend against malicious streams.
1996 *
1997 * @param s the stream to read
1998 * @throws InvalidObjectException always
1999 */
2000 @java.io.Serial
2001 private void readObject(ObjectInputStream s) throws InvalidObjectException {
2002 throw new InvalidObjectException("Deserialization via serialization delegate");
2003 }
2004
2005 void writeExternal(DataOutput out) throws IOException {
2006 date.writeExternal(out);
2007 time.writeExternal(out);
2008 }
2009
2010 static LocalDateTime readExternal(DataInput in) throws IOException {
2011 LocalDate date = LocalDate.readExternal(in);
2012 LocalTime time = LocalTime.readExternal(in);
2013 return LocalDateTime.of(date, time);
2014 }
2015
2016 }
|