Path: blob/master/src/java.base/share/classes/java/time/chrono/HijrahDate.java
41159 views
/*1* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos27*28* All rights reserved.29*30* Redistribution and use in source and binary forms, with or without31* modification, are permitted provided that the following conditions are met:32*33* * Redistributions of source code must retain the above copyright notice,34* this list of conditions and the following disclaimer.35*36* * Redistributions in binary form must reproduce the above copyright notice,37* this list of conditions and the following disclaimer in the documentation38* and/or other materials provided with the distribution.39*40* * Neither the name of JSR-310 nor the names of its contributors41* may be used to endorse or promote products derived from this software42* without specific prior written permission.43*44* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS45* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT46* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR47* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR48* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,49* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,50* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR51* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF52* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING53* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS54* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.55*/56package java.time.chrono;5758import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;59import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;60import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;61import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;62import static java.time.temporal.ChronoField.DAY_OF_MONTH;63import static java.time.temporal.ChronoField.MONTH_OF_YEAR;64import static java.time.temporal.ChronoField.YEAR;6566import java.io.IOException;67import java.io.InvalidObjectException;68import java.io.ObjectInput;69import java.io.ObjectInputStream;70import java.io.ObjectOutput;71import java.io.Serializable;72import java.time.Clock;73import java.time.DateTimeException;74import java.time.LocalDate;75import java.time.LocalTime;76import java.time.ZoneId;77import java.time.temporal.ChronoField;78import java.time.temporal.TemporalAccessor;79import java.time.temporal.TemporalAdjuster;80import java.time.temporal.TemporalAmount;81import java.time.temporal.TemporalField;82import java.time.temporal.TemporalQuery;83import java.time.temporal.TemporalUnit;84import java.time.temporal.UnsupportedTemporalTypeException;85import java.time.temporal.ValueRange;8687/**88* A date in the Hijrah calendar system.89* <p>90* This date operates using one of several variants of the91* {@linkplain HijrahChronology Hijrah calendar}.92* <p>93* The Hijrah calendar has a different total of days in a year than94* Gregorian calendar, and the length of each month is based on the period95* of a complete revolution of the moon around the earth96* (as between successive new moons).97* Refer to the {@link HijrahChronology} for details of supported variants.98* <p>99* Each HijrahDate is created bound to a particular HijrahChronology,100* The same chronology is propagated to each HijrahDate computed from the date.101* To use a different Hijrah variant, its HijrahChronology can be used102* to create new HijrahDate instances.103* Alternatively, the {@link #withVariant} method can be used to convert104* to a new HijrahChronology.105* <p>106* This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>107* class; programmers should treat instances that are108* {@linkplain #equals(Object) equal} as interchangeable and should not109* use instances for synchronization, or unpredictable behavior may110* occur. For example, in a future release, synchronization may fail.111* The {@code equals} method should be used for comparisons.112*113* @implSpec114* This class is immutable and thread-safe.115*116* @since 1.8117*/118@jdk.internal.ValueBased119public final class HijrahDate120extends ChronoLocalDateImpl<HijrahDate>121implements ChronoLocalDate, Serializable {122123/**124* Serialization version.125*/126@java.io.Serial127private static final long serialVersionUID = -5207853542612002020L;128/**129* The Chronology of this HijrahDate.130*/131private final transient HijrahChronology chrono;132/**133* The proleptic year.134*/135private final transient int prolepticYear;136/**137* The month-of-year.138*/139private final transient int monthOfYear;140/**141* The day-of-month.142*/143private final transient int dayOfMonth;144145//-------------------------------------------------------------------------146/**147* Obtains an instance of {@code HijrahDate} from the Hijrah proleptic year,148* month-of-year and day-of-month.149*150* @param prolepticYear the proleptic year to represent in the Hijrah calendar151* @param monthOfYear the month-of-year to represent, from 1 to 12152* @param dayOfMonth the day-of-month to represent, from 1 to 30153* @return the Hijrah date, never null154* @throws DateTimeException if the value of any field is out of range155*/156static HijrahDate of(HijrahChronology chrono, int prolepticYear, int monthOfYear, int dayOfMonth) {157return new HijrahDate(chrono, prolepticYear, monthOfYear, dayOfMonth);158}159160/**161* Returns a HijrahDate for the chronology and epochDay.162* @param chrono The Hijrah chronology163* @param epochDay the epoch day164* @return a HijrahDate for the epoch day; non-null165*/166static HijrahDate ofEpochDay(HijrahChronology chrono, long epochDay) {167return new HijrahDate(chrono, epochDay);168}169170//-----------------------------------------------------------------------171/**172* Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar173* in the default time-zone.174* <p>175* This will query the {@link Clock#systemDefaultZone() system clock} in the default176* time-zone to obtain the current date.177* <p>178* Using this method will prevent the ability to use an alternate clock for testing179* because the clock is hard-coded.180*181* @return the current date using the system clock and default time-zone, not null182*/183public static HijrahDate now() {184return now(Clock.systemDefaultZone());185}186187/**188* Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar189* in the specified time-zone.190* <p>191* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.192* Specifying the time-zone avoids dependence on the default time-zone.193* <p>194* Using this method will prevent the ability to use an alternate clock for testing195* because the clock is hard-coded.196*197* @param zone the zone ID to use, not null198* @return the current date using the system clock, not null199*/200public static HijrahDate now(ZoneId zone) {201return now(Clock.system(zone));202}203204/**205* Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar206* from the specified clock.207* <p>208* This will query the specified clock to obtain the current date - today.209* Using this method allows the use of an alternate clock for testing.210* The alternate clock may be introduced using {@linkplain Clock dependency injection}.211*212* @param clock the clock to use, not null213* @return the current date, not null214* @throws DateTimeException if the current date cannot be obtained215*/216public static HijrahDate now(Clock clock) {217return HijrahDate.ofEpochDay(HijrahChronology.INSTANCE, LocalDate.now(clock).toEpochDay());218}219220/**221* Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar222* from the proleptic-year, month-of-year and day-of-month fields.223* <p>224* This returns a {@code HijrahDate} with the specified fields.225* The day must be valid for the year and month, otherwise an exception will be thrown.226*227* @param prolepticYear the Hijrah proleptic-year228* @param month the Hijrah month-of-year, from 1 to 12229* @param dayOfMonth the Hijrah day-of-month, from 1 to 30230* @return the date in Hijrah calendar system, not null231* @throws DateTimeException if the value of any field is out of range,232* or if the day-of-month is invalid for the month-year233*/234public static HijrahDate of(int prolepticYear, int month, int dayOfMonth) {235return HijrahChronology.INSTANCE.date(prolepticYear, month, dayOfMonth);236}237238/**239* Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar from a temporal object.240* <p>241* This obtains a date in the Hijrah calendar system based on the specified temporal.242* A {@code TemporalAccessor} represents an arbitrary set of date and time information,243* which this factory converts to an instance of {@code HijrahDate}.244* <p>245* The conversion typically uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY}246* field, which is standardized across calendar systems.247* <p>248* This method matches the signature of the functional interface {@link TemporalQuery}249* allowing it to be used as a query via method reference, {@code HijrahDate::from}.250*251* @param temporal the temporal object to convert, not null252* @return the date in Hijrah calendar system, not null253* @throws DateTimeException if unable to convert to a {@code HijrahDate}254*/255public static HijrahDate from(TemporalAccessor temporal) {256return HijrahChronology.INSTANCE.date(temporal);257}258259//-----------------------------------------------------------------------260/**261* Constructs an {@code HijrahDate} with the proleptic-year, month-of-year and262* day-of-month fields.263*264* @param chrono The chronology to create the date with265* @param prolepticYear the proleptic year266* @param monthOfYear the month of year267* @param dayOfMonth the day of month268*/269private HijrahDate(HijrahChronology chrono, int prolepticYear, int monthOfYear, int dayOfMonth) {270// Computing the Gregorian day checks the valid ranges271chrono.getEpochDay(prolepticYear, monthOfYear, dayOfMonth);272273this.chrono = chrono;274this.prolepticYear = prolepticYear;275this.monthOfYear = monthOfYear;276this.dayOfMonth = dayOfMonth;277}278279/**280* Constructs an instance with the Epoch Day.281*282* @param epochDay the epochDay283*/284private HijrahDate(HijrahChronology chrono, long epochDay) {285int[] dateInfo = chrono.getHijrahDateInfo((int)epochDay);286287this.chrono = chrono;288this.prolepticYear = dateInfo[0];289this.monthOfYear = dateInfo[1];290this.dayOfMonth = dateInfo[2];291}292293//-----------------------------------------------------------------------294/**295* Gets the chronology of this date, which is the Hijrah calendar system.296* <p>297* The {@code Chronology} represents the calendar system in use.298* The era and other fields in {@link ChronoField} are defined by the chronology.299*300* @return the Hijrah chronology, not null301*/302@Override303public HijrahChronology getChronology() {304return chrono;305}306307/**308* Gets the era applicable at this date.309* <p>310* The Hijrah calendar system has one era, 'AH',311* defined by {@link HijrahEra}.312*313* @return the era applicable at this date, not null314*/315@Override316public HijrahEra getEra() {317return HijrahEra.AH;318}319320/**321* Returns the length of the month represented by this date.322* <p>323* This returns the length of the month in days.324* Month lengths in the Hijrah calendar system vary between 29 and 30 days.325*326* @return the length of the month in days327*/328@Override329public int lengthOfMonth() {330return chrono.getMonthLength(prolepticYear, monthOfYear);331}332333/**334* Returns the length of the year represented by this date.335* <p>336* This returns the length of the year in days.337* A Hijrah calendar system year is typically shorter than338* that of the ISO calendar system.339*340* @return the length of the year in days341*/342@Override343public int lengthOfYear() {344return chrono.getYearLength(prolepticYear);345}346347//-----------------------------------------------------------------------348@Override349public ValueRange range(TemporalField field) {350if (field instanceof ChronoField) {351if (isSupported(field)) {352ChronoField f = (ChronoField) field;353switch (f) {354case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());355case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());356case ALIGNED_WEEK_OF_MONTH: return ValueRange.of(1, 5); // TODO357// TODO does the limited range of valid years cause years to358// start/end part way through? that would affect range359}360return getChronology().range(f);361}362throw new UnsupportedTemporalTypeException("Unsupported field: " + field);363}364return field.rangeRefinedBy(this);365}366367@Override368public long getLong(TemporalField field) {369if (field instanceof ChronoField) {370switch ((ChronoField) field) {371case DAY_OF_WEEK: return getDayOfWeek();372case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1;373case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;374case DAY_OF_MONTH: return this.dayOfMonth;375case DAY_OF_YEAR: return this.getDayOfYear();376case EPOCH_DAY: return toEpochDay();377case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1;378case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;379case MONTH_OF_YEAR: return monthOfYear;380case PROLEPTIC_MONTH: return getProlepticMonth();381case YEAR_OF_ERA: return prolepticYear;382case YEAR: return prolepticYear;383case ERA: return getEraValue();384}385throw new UnsupportedTemporalTypeException("Unsupported field: " + field);386}387return field.getFrom(this);388}389390private long getProlepticMonth() {391return prolepticYear * 12L + monthOfYear - 1;392}393394@Override395public HijrahDate with(TemporalField field, long newValue) {396if (field instanceof ChronoField chronoField) {397// not using checkValidIntValue so EPOCH_DAY and PROLEPTIC_MONTH work398chrono.range(chronoField).checkValidValue(newValue, chronoField); // TODO: validate value399int nvalue = (int) newValue;400switch (chronoField) {401case DAY_OF_WEEK: return plusDays(newValue - getDayOfWeek());402case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));403case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));404case DAY_OF_MONTH: return resolvePreviousValid(prolepticYear, monthOfYear, nvalue);405case DAY_OF_YEAR: return plusDays(Math.min(nvalue, lengthOfYear()) - getDayOfYear());406case EPOCH_DAY: return new HijrahDate(chrono, newValue);407case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);408case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);409case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, dayOfMonth);410case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());411case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth);412case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);413case ERA: return resolvePreviousValid(1 - prolepticYear, monthOfYear, dayOfMonth);414}415throw new UnsupportedTemporalTypeException("Unsupported field: " + field);416}417return super.with(field, newValue);418}419420private HijrahDate resolvePreviousValid(int prolepticYear, int month, int day) {421int monthDays = chrono.getMonthLength(prolepticYear, month);422if (day > monthDays) {423day = monthDays;424}425return HijrahDate.of(chrono, prolepticYear, month, day);426}427428/**429* {@inheritDoc}430* @throws DateTimeException if unable to make the adjustment.431* For example, if the adjuster requires an ISO chronology432* @throws ArithmeticException {@inheritDoc}433*/434@Override435public HijrahDate with(TemporalAdjuster adjuster) {436return super.with(adjuster);437}438439/**440* Returns a {@code HijrahDate} with the Chronology requested.441* <p>442* The year, month, and day are checked against the new requested443* HijrahChronology. If the chronology has a shorter month length444* for the month, the day is reduced to be the last day of the month.445*446* @param chronology the new HijrahChonology, non-null447* @return a HijrahDate with the requested HijrahChronology, non-null448*/449public HijrahDate withVariant(HijrahChronology chronology) {450if (chrono == chronology) {451return this;452}453// Like resolvePreviousValid the day is constrained to stay in the same month454int monthDays = chronology.getDayOfYear(prolepticYear, monthOfYear);455return HijrahDate.of(chronology, prolepticYear, monthOfYear,(dayOfMonth > monthDays) ? monthDays : dayOfMonth );456}457458/**459* {@inheritDoc}460* @throws DateTimeException {@inheritDoc}461* @throws ArithmeticException {@inheritDoc}462*/463@Override464public HijrahDate plus(TemporalAmount amount) {465return super.plus(amount);466}467468/**469* {@inheritDoc}470* @throws DateTimeException {@inheritDoc}471* @throws ArithmeticException {@inheritDoc}472*/473@Override474public HijrahDate minus(TemporalAmount amount) {475return super.minus(amount);476}477478@Override479public long toEpochDay() {480return chrono.getEpochDay(prolepticYear, monthOfYear, dayOfMonth);481}482483/**484* Gets the day-of-year field.485* <p>486* This method returns the primitive {@code int} value for the day-of-year.487*488* @return the day-of-year489*/490private int getDayOfYear() {491return chrono.getDayOfYear(prolepticYear, monthOfYear) + dayOfMonth;492}493494/**495* Gets the day-of-week value.496*497* @return the day-of-week; computed from the epochday498*/499private int getDayOfWeek() {500int dow0 = Math.floorMod(toEpochDay() + 3, 7);501return dow0 + 1;502}503504/**505* Gets the Era of this date.506*507* @return the Era of this date; computed from epochDay508*/509private int getEraValue() {510return (prolepticYear > 1 ? 1 : 0);511}512513//-----------------------------------------------------------------------514/**515* Checks if the year is a leap year, according to the Hijrah calendar system rules.516*517* @return true if this date is in a leap year518*/519@Override520public boolean isLeapYear() {521return chrono.isLeapYear(prolepticYear);522}523524//-----------------------------------------------------------------------525@Override526HijrahDate plusYears(long years) {527if (years == 0) {528return this;529}530int newYear = Math.addExact(this.prolepticYear, (int)years);531return resolvePreviousValid(newYear, monthOfYear, dayOfMonth);532}533534@Override535HijrahDate plusMonths(long monthsToAdd) {536if (monthsToAdd == 0) {537return this;538}539long monthCount = prolepticYear * 12L + (monthOfYear - 1);540long calcMonths = monthCount + monthsToAdd; // safe overflow541int newYear = chrono.checkValidYear(Math.floorDiv(calcMonths, 12L));542int newMonth = (int)Math.floorMod(calcMonths, 12L) + 1;543return resolvePreviousValid(newYear, newMonth, dayOfMonth);544}545546@Override547HijrahDate plusWeeks(long weeksToAdd) {548return super.plusWeeks(weeksToAdd);549}550551@Override552HijrahDate plusDays(long days) {553return new HijrahDate(chrono, toEpochDay() + days);554}555556@Override557public HijrahDate plus(long amountToAdd, TemporalUnit unit) {558return super.plus(amountToAdd, unit);559}560561@Override562public HijrahDate minus(long amountToSubtract, TemporalUnit unit) {563return super.minus(amountToSubtract, unit);564}565566@Override567HijrahDate minusYears(long yearsToSubtract) {568return super.minusYears(yearsToSubtract);569}570571@Override572HijrahDate minusMonths(long monthsToSubtract) {573return super.minusMonths(monthsToSubtract);574}575576@Override577HijrahDate minusWeeks(long weeksToSubtract) {578return super.minusWeeks(weeksToSubtract);579}580581@Override582HijrahDate minusDays(long daysToSubtract) {583return super.minusDays(daysToSubtract);584}585586@Override // for javadoc and covariant return type587@SuppressWarnings("unchecked")588public final ChronoLocalDateTime<HijrahDate> atTime(LocalTime localTime) {589return (ChronoLocalDateTime<HijrahDate>)super.atTime(localTime);590}591592@Override593public ChronoPeriod until(ChronoLocalDate endDate) {594// TODO: untested595HijrahDate end = getChronology().date(endDate);596long totalMonths = (end.prolepticYear - this.prolepticYear) * 12 + (end.monthOfYear - this.monthOfYear); // safe597int days = end.dayOfMonth - this.dayOfMonth;598if (totalMonths > 0 && days < 0) {599totalMonths--;600HijrahDate calcDate = this.plusMonths(totalMonths);601days = (int) (end.toEpochDay() - calcDate.toEpochDay()); // safe602} else if (totalMonths < 0 && days > 0) {603totalMonths++;604days -= end.lengthOfMonth();605}606long years = totalMonths / 12; // safe607int months = (int) (totalMonths % 12); // safe608return getChronology().period(Math.toIntExact(years), months, days);609}610611//-------------------------------------------------------------------------612/**613* Compares this date to another date, including the chronology.614* <p>615* Compares this {@code HijrahDate} with another ensuring that the date is the same.616* <p>617* Only objects of type {@code HijrahDate} are compared, other types return false.618* To compare the dates of two {@code TemporalAccessor} instances, including dates619* in two different chronologies, use {@link ChronoField#EPOCH_DAY} as a comparator.620*621* @param obj the object to check, null returns false622* @return true if this is equal to the other date and the Chronologies are equal623*/624@Override // override for performance625public boolean equals(Object obj) {626if (this == obj) {627return true;628}629return (obj instanceof HijrahDate otherDate)630&& prolepticYear == otherDate.prolepticYear631&& this.monthOfYear == otherDate.monthOfYear632&& this.dayOfMonth == otherDate.dayOfMonth633&& getChronology().equals(otherDate.getChronology());634}635636/**637* A hash code for this date.638*639* @return a suitable hash code based only on the Chronology and the date640*/641@Override // override for performance642public int hashCode() {643int yearValue = prolepticYear;644int monthValue = monthOfYear;645int dayValue = dayOfMonth;646return getChronology().getId().hashCode() ^ (yearValue & 0xFFFFF800)647^ ((yearValue << 11) + (monthValue << 6) + (dayValue));648}649650//-----------------------------------------------------------------------651/**652* Defend against malicious streams.653*654* @param s the stream to read655* @throws InvalidObjectException always656*/657@java.io.Serial658private void readObject(ObjectInputStream s) throws InvalidObjectException {659throw new InvalidObjectException("Deserialization via serialization delegate");660}661662/**663* Writes the object using a664* <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.665* @serialData666* <pre>667* out.writeByte(6); // identifies a HijrahDate668* out.writeObject(chrono); // the HijrahChronology variant669* out.writeInt(get(YEAR));670* out.writeByte(get(MONTH_OF_YEAR));671* out.writeByte(get(DAY_OF_MONTH));672* </pre>673*674* @return the instance of {@code Ser}, not null675*/676@java.io.Serial677private Object writeReplace() {678return new Ser(Ser.HIJRAH_DATE_TYPE, this);679}680681void writeExternal(ObjectOutput out) throws IOException {682// HijrahChronology is implicit in the Hijrah_DATE_TYPE683out.writeObject(getChronology());684out.writeInt(get(YEAR));685out.writeByte(get(MONTH_OF_YEAR));686out.writeByte(get(DAY_OF_MONTH));687}688689static HijrahDate readExternal(ObjectInput in) throws IOException, ClassNotFoundException {690HijrahChronology chrono = (HijrahChronology) in.readObject();691int year = in.readInt();692int month = in.readByte();693int dayOfMonth = in.readByte();694return chrono.date(year, month, dayOfMonth);695}696697}698699700