< prev index next >

src/java.base/share/classes/java/time/OffsetTime.java

Print this page




 121     /**
 122      * The minimum supported {@code OffsetTime}, '00:00:00+18:00'.
 123      * This is the time of midnight at the start of the day in the maximum offset
 124      * (larger offsets are earlier on the time-line).
 125      * This combines {@link LocalTime#MIN} and {@link ZoneOffset#MAX}.
 126      * This could be used by an application as a "far past" date.
 127      */
 128     public static final OffsetTime MIN = LocalTime.MIN.atOffset(ZoneOffset.MAX);
 129     /**
 130      * The maximum supported {@code OffsetTime}, '23:59:59.999999999-18:00'.
 131      * This is the time just before midnight at the end of the day in the minimum offset
 132      * (larger negative offsets are later on the time-line).
 133      * This combines {@link LocalTime#MAX} and {@link ZoneOffset#MIN}.
 134      * This could be used by an application as a "far future" date.
 135      */
 136     public static final OffsetTime MAX = LocalTime.MAX.atOffset(ZoneOffset.MIN);
 137 
 138     /**
 139      * Serialization version.
 140      */

 141     private static final long serialVersionUID = 7264499704384272492L;
 142 
 143     /**
 144      * The local date-time.
 145      */
 146     private final LocalTime time;
 147     /**
 148      * The offset from UTC/Greenwich.
 149      */
 150     private final ZoneOffset offset;
 151 
 152     //-----------------------------------------------------------------------
 153     /**
 154      * Obtains the current time from the system clock in the default time-zone.
 155      * <p>
 156      * This will query the {@link Clock#systemDefaultZone() system clock} in the default
 157      * time-zone to obtain the current time.
 158      * The offset will be calculated from the time-zone in the clock.
 159      * <p>
 160      * Using this method will prevent the ability to use an alternate clock for testing


1393      * @return a string representation of this time, not null
1394      */
1395     @Override
1396     public String toString() {
1397         return time.toString() + offset.toString();
1398     }
1399 
1400     //-----------------------------------------------------------------------
1401     /**
1402      * Writes the object using a
1403      * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1404      * @serialData
1405      * <pre>
1406      *  out.writeByte(9);  // identifies an OffsetTime
1407      *  // the <a href="{@docRoot}/serialized-form.html#java.time.LocalTime">time</a> excluding the one byte header
1408      *  // the <a href="{@docRoot}/serialized-form.html#java.time.ZoneOffset">offset</a> excluding the one byte header
1409      * </pre>
1410      *
1411      * @return the instance of {@code Ser}, not null
1412      */

1413     private Object writeReplace() {
1414         return new Ser(Ser.OFFSET_TIME_TYPE, this);
1415     }
1416 
1417     /**
1418      * Defend against malicious streams.
1419      *
1420      * @param s the stream to read
1421      * @throws InvalidObjectException always
1422      */

1423     private void readObject(ObjectInputStream s) throws InvalidObjectException {
1424         throw new InvalidObjectException("Deserialization via serialization delegate");
1425     }
1426 
1427     void writeExternal(ObjectOutput out) throws IOException {
1428         time.writeExternal(out);
1429         offset.writeExternal(out);
1430     }
1431 
1432     static OffsetTime readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
1433         LocalTime time = LocalTime.readExternal(in);
1434         ZoneOffset offset = ZoneOffset.readExternal(in);
1435         return OffsetTime.of(time, offset);
1436     }
1437 
1438 }


 121     /**
 122      * The minimum supported {@code OffsetTime}, '00:00:00+18:00'.
 123      * This is the time of midnight at the start of the day in the maximum offset
 124      * (larger offsets are earlier on the time-line).
 125      * This combines {@link LocalTime#MIN} and {@link ZoneOffset#MAX}.
 126      * This could be used by an application as a "far past" date.
 127      */
 128     public static final OffsetTime MIN = LocalTime.MIN.atOffset(ZoneOffset.MAX);
 129     /**
 130      * The maximum supported {@code OffsetTime}, '23:59:59.999999999-18:00'.
 131      * This is the time just before midnight at the end of the day in the minimum offset
 132      * (larger negative offsets are later on the time-line).
 133      * This combines {@link LocalTime#MAX} and {@link ZoneOffset#MIN}.
 134      * This could be used by an application as a "far future" date.
 135      */
 136     public static final OffsetTime MAX = LocalTime.MAX.atOffset(ZoneOffset.MIN);
 137 
 138     /**
 139      * Serialization version.
 140      */
 141     @java.io.Serial
 142     private static final long serialVersionUID = 7264499704384272492L;
 143 
 144     /**
 145      * The local date-time.
 146      */
 147     private final LocalTime time;
 148     /**
 149      * The offset from UTC/Greenwich.
 150      */
 151     private final ZoneOffset offset;
 152 
 153     //-----------------------------------------------------------------------
 154     /**
 155      * Obtains the current time from the system clock in the default time-zone.
 156      * <p>
 157      * This will query the {@link Clock#systemDefaultZone() system clock} in the default
 158      * time-zone to obtain the current time.
 159      * The offset will be calculated from the time-zone in the clock.
 160      * <p>
 161      * Using this method will prevent the ability to use an alternate clock for testing


1394      * @return a string representation of this time, not null
1395      */
1396     @Override
1397     public String toString() {
1398         return time.toString() + offset.toString();
1399     }
1400 
1401     //-----------------------------------------------------------------------
1402     /**
1403      * Writes the object using a
1404      * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1405      * @serialData
1406      * <pre>
1407      *  out.writeByte(9);  // identifies an OffsetTime
1408      *  // the <a href="{@docRoot}/serialized-form.html#java.time.LocalTime">time</a> excluding the one byte header
1409      *  // the <a href="{@docRoot}/serialized-form.html#java.time.ZoneOffset">offset</a> excluding the one byte header
1410      * </pre>
1411      *
1412      * @return the instance of {@code Ser}, not null
1413      */
1414     @java.io.Serial
1415     private Object writeReplace() {
1416         return new Ser(Ser.OFFSET_TIME_TYPE, this);
1417     }
1418 
1419     /**
1420      * Defend against malicious streams.
1421      *
1422      * @param s the stream to read
1423      * @throws InvalidObjectException always
1424      */
1425     @java.io.Serial
1426     private void readObject(ObjectInputStream s) throws InvalidObjectException {
1427         throw new InvalidObjectException("Deserialization via serialization delegate");
1428     }
1429 
1430     void writeExternal(ObjectOutput out) throws IOException {
1431         time.writeExternal(out);
1432         offset.writeExternal(out);
1433     }
1434 
1435     static OffsetTime readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
1436         LocalTime time = LocalTime.readExternal(in);
1437         ZoneOffset offset = ZoneOffset.readExternal(in);
1438         return OffsetTime.of(time, offset);
1439     }
1440 
1441 }
< prev index next >