< prev index next >

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

Print this page




 140         implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable {
 141 
 142     /**
 143      * The minimum supported {@code LocalDate}, '-999999999-01-01'.
 144      * This could be used by an application as a "far past" date.
 145      */
 146     public static final LocalDate MIN = LocalDate.of(Year.MIN_VALUE, 1, 1);
 147     /**
 148      * The maximum supported {@code LocalDate}, '+999999999-12-31'.
 149      * This could be used by an application as a "far future" date.
 150      */
 151     public static final LocalDate MAX = LocalDate.of(Year.MAX_VALUE, 12, 31);
 152     /**
 153      * The epoch year {@code LocalDate}, '1970-01-01'.
 154      */
 155     public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
 156 
 157     /**
 158      * Serialization version.
 159      */

 160     private static final long serialVersionUID = 2942565459149668126L;
 161     /**
 162      * The number of days in a 400 year cycle.
 163      */
 164     private static final int DAYS_PER_CYCLE = 146097;
 165     /**
 166      * The number of days from year zero to year 1970.
 167      * There are five 400 year cycles from year zero to 2000.
 168      * There are 7 leap years from 1970 to 2000.
 169      */
 170     static final long DAYS_0000_TO_1970 = (DAYS_PER_CYCLE * 5L) - (30L * 365L + 7L);
 171 
 172     /**
 173      * The year.
 174      */
 175     private final int year;
 176     /**
 177      * The month-of-year.
 178      */
 179     private final short month;


2183             .append(monthValue)
2184             .append(dayValue < 10 ? "-0" : "-")
2185             .append(dayValue)
2186             .toString();
2187     }
2188 
2189     //-----------------------------------------------------------------------
2190     /**
2191      * Writes the object using a
2192      * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
2193      * @serialData
2194      * <pre>
2195      *  out.writeByte(3);  // identifies a LocalDate
2196      *  out.writeInt(year);
2197      *  out.writeByte(month);
2198      *  out.writeByte(day);
2199      * </pre>
2200      *
2201      * @return the instance of {@code Ser}, not null
2202      */

2203     private Object writeReplace() {
2204         return new Ser(Ser.LOCAL_DATE_TYPE, this);
2205     }
2206 
2207     /**
2208      * Defend against malicious streams.
2209      *
2210      * @param s the stream to read
2211      * @throws InvalidObjectException always
2212      */

2213     private void readObject(ObjectInputStream s) throws InvalidObjectException {
2214         throw new InvalidObjectException("Deserialization via serialization delegate");
2215     }
2216 
2217     void writeExternal(DataOutput out) throws IOException {
2218         out.writeInt(year);
2219         out.writeByte(month);
2220         out.writeByte(day);
2221     }
2222 
2223     static LocalDate readExternal(DataInput in) throws IOException {
2224         int year = in.readInt();
2225         int month = in.readByte();
2226         int dayOfMonth = in.readByte();
2227         return LocalDate.of(year, month, dayOfMonth);
2228     }
2229 
2230 }


 140         implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable {
 141 
 142     /**
 143      * The minimum supported {@code LocalDate}, '-999999999-01-01'.
 144      * This could be used by an application as a "far past" date.
 145      */
 146     public static final LocalDate MIN = LocalDate.of(Year.MIN_VALUE, 1, 1);
 147     /**
 148      * The maximum supported {@code LocalDate}, '+999999999-12-31'.
 149      * This could be used by an application as a "far future" date.
 150      */
 151     public static final LocalDate MAX = LocalDate.of(Year.MAX_VALUE, 12, 31);
 152     /**
 153      * The epoch year {@code LocalDate}, '1970-01-01'.
 154      */
 155     public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
 156 
 157     /**
 158      * Serialization version.
 159      */
 160     @java.io.Serial
 161     private static final long serialVersionUID = 2942565459149668126L;
 162     /**
 163      * The number of days in a 400 year cycle.
 164      */
 165     private static final int DAYS_PER_CYCLE = 146097;
 166     /**
 167      * The number of days from year zero to year 1970.
 168      * There are five 400 year cycles from year zero to 2000.
 169      * There are 7 leap years from 1970 to 2000.
 170      */
 171     static final long DAYS_0000_TO_1970 = (DAYS_PER_CYCLE * 5L) - (30L * 365L + 7L);
 172 
 173     /**
 174      * The year.
 175      */
 176     private final int year;
 177     /**
 178      * The month-of-year.
 179      */
 180     private final short month;


2184             .append(monthValue)
2185             .append(dayValue < 10 ? "-0" : "-")
2186             .append(dayValue)
2187             .toString();
2188     }
2189 
2190     //-----------------------------------------------------------------------
2191     /**
2192      * Writes the object using a
2193      * <a href="{@docRoot}/serialized-form.html#java.time.Ser">dedicated serialized form</a>.
2194      * @serialData
2195      * <pre>
2196      *  out.writeByte(3);  // identifies a LocalDate
2197      *  out.writeInt(year);
2198      *  out.writeByte(month);
2199      *  out.writeByte(day);
2200      * </pre>
2201      *
2202      * @return the instance of {@code Ser}, not null
2203      */
2204     @java.io.Serial
2205     private Object writeReplace() {
2206         return new Ser(Ser.LOCAL_DATE_TYPE, this);
2207     }
2208 
2209     /**
2210      * Defend against malicious streams.
2211      *
2212      * @param s the stream to read
2213      * @throws InvalidObjectException always
2214      */
2215     @java.io.Serial
2216     private void readObject(ObjectInputStream s) throws InvalidObjectException {
2217         throw new InvalidObjectException("Deserialization via serialization delegate");
2218     }
2219 
2220     void writeExternal(DataOutput out) throws IOException {
2221         out.writeInt(year);
2222         out.writeByte(month);
2223         out.writeByte(day);
2224     }
2225 
2226     static LocalDate readExternal(DataInput in) throws IOException {
2227         int year = in.readInt();
2228         int month = in.readByte();
2229         int dayOfMonth = in.readByte();
2230         return LocalDate.of(year, month, dayOfMonth);
2231     }
2232 
2233 }
< prev index next >