This date operates using the Japanese Imperial calendar. This calendar system is primarily used in Japan.
The Japanese Imperial calendar system is the same as the ISO calendar system apart from the era-based year numbering. The proleptic-year is defined to be equal to the ISO proleptic-year.
Japan introduced the Gregorian calendar starting with Meiji 6. Only Meiji and later eras are supported; dates before Meiji 6, January 1 are not supported.
For example, the Japanese year "Heisei 24" corresponds to ISO year "2012".
Calling japaneseDate.get(YEAR_OF_ERA)
will return 24.
Calling japaneseDate.get(YEAR)
will return 2012.
Calling japaneseDate.get(ERA)
will return 2, corresponding to
JapaneseChronology.ERA_HEISEI
.
This is a value-based
class; programmers should treat instances that are
equal as interchangeable and should not
use instances for synchronization, or unpredictable behavior may
occur. For example, in a future release, synchronization may fail.
The equals
method should be used for comparisons.
Implementation Specification
This class is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
private final transient JapaneseEra | era
The JapaneseEra of this date. |
private final transient LocalDate | isoDate
The underlying ISO local date. |
pack-priv static final LocalDate | MEIJI_6_ISODATE
The first day supported by the JapaneseChronology is Meiji 6, January 1st. |
private static final long | serialVersionUID
Hides java. |
private final transient int | yearOfEra
The Japanese imperial calendar year of this date. |
Access | Constructor and Description |
---|---|
pack-priv | JapaneseDate(LocalDate
the standard local date, validated not null isoDate)Creates an instance from an ISO date. |
pack-priv | JapaneseDate(JapaneseEra
the era, validated not null era, int the year-of-era, validated year, LocalDate the standard local date, validated not null isoDate)Constructs a |
Modifier and Type | Method and Description |
---|---|
public final ChronoLocalDateTime | atTime(LocalTime
the local time to use, not null localTime)Overrides default java. Combines this date with a time to create a |
public boolean | Returns: true if this is equal to the other datethe object to check, null returns false obj)Overrides java. Implements java. Compares this date to another date, including the chronology. |
public static JapaneseDate | Returns: the date in Japanese calendar system, not nullthe temporal object to convert, not null temporal)Hides java. Obtains a |
public JapaneseChronology | Returns: the Japanese chronology, not nullImplements java. Gets the chronology of this date, which is the Japanese calendar system. |
public JapaneseEra | Returns: the era applicable at this date, not nullOverrides default java. Gets the era applicable at this date. |
public long | getLong(TemporalField
the field to get, not null field)Implements java. Gets the value of the specified field as a |
public int | Returns: a suitable hash code based only on the Chronology and the dateOverrides java. Implements java. A hash code for this date. |
public boolean | Returns: true if the field is supported on this date, false if notthe field to check, null returns false field)Overrides default java. Implements java. Checks if the specified field is supported. |
public int | Returns: the length of the month in daysImplements java. Returns the length of the month represented by this date. |
public int | lengthOfYear()
Overrides default java. Returns the length of the year represented by this date, as defined by the calendar system. |
public JapaneseDate | minus(TemporalAmount
the amount to subtract, not null amount)Overrides java. Overrides default java. Returns an object of the same type as this object with an amount subtracted. |
public JapaneseDate | minus(long
the amount of the specified unit to subtract, may be negative amountToSubtract, TemporalUnit the unit of the amount to subtract, not null unit)Overrides java. Overrides default java. Returns an object of the same type as this object with the specified period subtracted. |
pack-priv JapaneseDate | minusDays(long
the days to subtract, may be negative daysToSubtract)Overrides java. Returns a copy of this date with the specified number of days subtracted. |
pack-priv JapaneseDate | minusMonths(long
the months to subtract, may be negative monthsToSubtract)Overrides java. Returns a copy of this date with the specified number of months subtracted. |
pack-priv JapaneseDate | minusWeeks(long
the weeks to subtract, may be negative weeksToSubtract)Overrides java. Returns a copy of this date with the specified number of weeks subtracted. |
pack-priv JapaneseDate | minusYears(long
the years to subtract, may be negative yearsToSubtract)Overrides java. Returns a copy of this date with the specified number of years subtracted. |
public static JapaneseDate | Returns: the current date using the system clock and default time-zone, not nullObtains the current |
public static JapaneseDate | |
public static JapaneseDate | |
public static JapaneseDate | Returns: the date in Japanese calendar system, not nullthe Japanese era, not null era, int the Japanese year-of-era yearOfEra, int the Japanese month-of-year, from 1 to 12 month, int the Japanese day-of-month, from 1 to 31 dayOfMonth)Obtains a |
public static JapaneseDate | Returns: the date in Japanese calendar system, not nullthe Japanese proleptic-year prolepticYear, int the Japanese month-of-year, from 1 to 12 month, int the Japanese day-of-month, from 1 to 31 dayOfMonth)Obtains a |
pack-priv static JapaneseDate | Returns: the date in Japanese calendar system, not nullthe Japanese era, not null era, int the Japanese year-of-era yearOfEra, int the chronology day-of-year, from 1 to 366 dayOfYear)Obtains a |
public JapaneseDate | plus(TemporalAmount
the amount to add, not null amount)Overrides java. Overrides default java. Returns an object of the same type as this object with an amount added. |
public JapaneseDate | plus(long
the amount of the specified unit to add, may be negative amountToAdd, TemporalUnit the unit of the amount to add, not null unit)Overrides java. Overrides default java. Implements java. Returns an object of the same type as this object with the specified period added. |
pack-priv JapaneseDate | plusDays(long
the days to add, may be negative days)Implements abstract java. Returns a copy of this date with the specified number of days added. |
pack-priv JapaneseDate | plusMonths(long
the months to add, may be negative months)Implements abstract java. Returns a copy of this date with the specified number of months added. |
pack-priv JapaneseDate | plusWeeks(long
the weeks to add, may be negative weeksToAdd)Overrides java. Returns a copy of this date with the specified number of weeks added. |
pack-priv JapaneseDate | plusYears(long
the years to add, may be negative years)Implements abstract java. Returns a copy of this date with the specified number of years added. |
public ValueRange | range(TemporalField
the field to query the range for, not null field)Overrides default java. Gets the range of valid values for the specified field. |
pack-priv static JapaneseDate | |
private void | |
public long | toEpochDay()
Overrides default java. Converts this date to the Epoch Day. |
private static LocalGregorianCalendar. | Returns: aLocalGregorianCalendar.Date , not nullthe local date, not null isoDate)Returns a |
public ChronoPeriod | until(ChronoLocalDate
the end date, exclusive, which may be in any chronology, not null endDate)Implements java. Calculates the period between this date and another date as a |
public JapaneseDate | with(TemporalField
the field to set in the result, not null field, long the new value of the field in the result newValue)Overrides java. Overrides default java. Implements java. Returns an object of the same type as this object with the specified field altered. |
public JapaneseDate | with(TemporalAdjuster
the adjuster to use, not null adjuster)Overrides java. Overrides default java. Returns an adjusted object of the same type as this object with the adjustment made. |
private JapaneseDate | |
private JapaneseDate | Returns: aJapaneseDate based on this date with the requested year, never nullthe era to set in the result, not null era, int the year-of-era to set in the returned date yearOfEra)Returns a copy of this date with the year altered. |
private JapaneseDate | Returns: aJapaneseDate based on this date with the requested year-of-era, never nullthe year to set in the returned date year)Returns a copy of this date with the year-of-era altered. |
pack-priv void | |
private Object | Returns: the instance ofSer , not nullWrites the object using a dedicated serialized form. |
era | back to summary |
---|---|
private final transient JapaneseEra era The JapaneseEra of this date. |
isoDate | back to summary |
---|---|
private final transient LocalDate isoDate The underlying ISO local date. |
MEIJI_6_ISODATE | back to summary |
---|---|
pack-priv static final LocalDate MEIJI_6_ISODATE The first day supported by the JapaneseChronology is Meiji 6, January 1st. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Serialization version. |
yearOfEra | back to summary |
---|---|
private final transient int yearOfEra The Japanese imperial calendar year of this date. |
JapaneseDate | back to summary |
---|---|
pack-priv JapaneseDate(LocalDate isoDate) Creates an instance from an ISO date.
|
JapaneseDate | back to summary |
---|---|
pack-priv JapaneseDate(JapaneseEra era, int year, LocalDate isoDate) Constructs a
|
atTime | back to summary |
---|---|
public final ChronoLocalDateTime Overrides default java. Doc from java. Combines this date with a time to create a
This returns a
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Implements java. Compares this date to another date, including the chronology.
Compares this
Only objects of type |
from | back to summary |
---|---|
public static JapaneseDate from(TemporalAccessor temporal) Hides java. Obtains a
This obtains a date in the Japanese calendar system based on the specified temporal.
A
The conversion typically uses the
This method matches the signature of the functional interface
|
getChronology | back to summary |
---|---|
public JapaneseChronology getChronology() Implements java. Gets the chronology of this date, which is the Japanese calendar system.
The
|
getEra | back to summary |
---|---|
public JapaneseEra getEra() Overrides default java. Gets the era applicable at this date.
The Japanese calendar system has multiple eras defined by
|
getLong | back to summary |
---|---|
public long getLong(TemporalField field) Implements java. Doc from java. Gets the value of the specified field as a This queries the date-time for the value of the specified field. The returned value may be outside the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Implements java. A hash code for this date.
|
isSupported | back to summary |
---|---|
public boolean isSupported(TemporalField field) Overrides default java. Implements java. Checks if the specified field is supported.
This checks if this date can be queried for the specified field.
If false, then calling the
If the field is a
ChronoField instances will return false.
If the field is not a
|
lengthOfMonth | back to summary |
---|---|
public int lengthOfMonth() Implements java. Returns the length of the month represented by this date. This returns the length of the month in days. Month lengths match those of the ISO calendar system.
|
lengthOfYear | back to summary |
---|---|
public int lengthOfYear() Overrides default java. Doc from java. Returns the length of the year represented by this date, as defined by the calendar system. This returns the length of the year in days.
The default implementation uses
|
minus | back to summary |
---|---|
public JapaneseDate minus(TemporalAmount amount) Overrides java. Overrides default java. Doc from java. Returns an object of the same type as this object with an amount subtracted.
This adjusts this temporal, subtracting according to the rules of the specified amount.
The amount is typically a Some example code indicating how and why this method is used: date = date.minus(period); // subtract a Period instance date = date.minus(duration); // subtract a Duration instance date = date.minus(workingDays(6)); // example user-written workingDays method
Note that calling
|
minus | back to summary |
---|---|
public JapaneseDate minus(long amountToSubtract, TemporalUnit unit) Overrides java. Overrides default java. Doc from java. Returns an object of the same type as this object with the specified period subtracted.
This method returns a new object based on this one with the specified period subtracted.
For example, on a In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st March, then subtracting one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
|
minusDays | back to summary |
---|---|
pack-priv JapaneseDate minusDays(long daysToSubtract) Overrides java. Doc from java. Returns a copy of this date with the specified number of days subtracted. This subtracts the specified period in days to the date.
The default implementation uses This instance is immutable and unaffected by this method call.
|
minusMonths | back to summary |
---|---|
pack-priv JapaneseDate minusMonths(long monthsToSubtract) Overrides java. Doc from java. Returns a copy of this date with the specified number of months subtracted. This subtracts the specified period in months to the date. In some cases, subtracting months can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month.
The default implementation uses This instance is immutable and unaffected by this method call.
|
minusWeeks | back to summary |
---|---|
pack-priv JapaneseDate minusWeeks(long weeksToSubtract) Overrides java. Doc from java. Returns a copy of this date with the specified number of weeks subtracted. This subtracts the specified period in weeks to the date. In some cases, subtracting weeks can cause the resulting date to become invalid. If this occurs, then other fields will be adjusted to ensure that the result is valid.
The default implementation uses This instance is immutable and unaffected by this method call.
|
minusYears | back to summary |
---|---|
pack-priv JapaneseDate minusYears(long yearsToSubtract) Overrides java. Doc from java. Returns a copy of this date with the specified number of years subtracted. This subtracts the specified period in years to the date. In some cases, subtracting years can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month.
The default implementation uses This instance is immutable and unaffected by this method call.
|
now | back to summary |
---|---|
public static JapaneseDate now() Obtains the current
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
|
now | back to summary |
---|---|
public static JapaneseDate now(ZoneId zone) Obtains the current
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
|
now | back to summary |
---|---|
public static JapaneseDate now(Clock clock) Obtains the current This will query the specified clock to obtain the current date - today. Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using dependency injection.
|
of | back to summary |
---|---|
public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) Obtains a
This returns a The Japanese month and day-of-month are the same as those in the ISO calendar system. They are not reset when the era changes. For example: 6th Jan Showa 64 = ISO 1989-01-06 7th Jan Showa 64 = ISO 1989-01-07 8th Jan Heisei 1 = ISO 1989-01-08 9th Jan Heisei 1 = ISO 1989-01-09
|
of | back to summary |
---|---|
public static JapaneseDate of(int prolepticYear, int month, int dayOfMonth) Obtains a
This returns a The Japanese proleptic year, month and day-of-month are the same as those in the ISO calendar system. They are not reset when the era changes.
|
ofYearDay | back to summary |
---|---|
pack-priv static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) Obtains a
This returns a The day-of-year in this factory is expressed relative to the start of the year-of-era. This definition changes the normal meaning of day-of-year only in those years where the year-of-era is reset to one due to a change in the era. For example: 6th Jan Showa 64 = day-of-year 6 7th Jan Showa 64 = day-of-year 7 8th Jan Heisei 1 = day-of-year 1 9th Jan Heisei 1 = day-of-year 2
|
plus | back to summary |
---|---|
public JapaneseDate plus(TemporalAmount amount) Overrides java. Overrides default java. Doc from java. Returns an object of the same type as this object with an amount added.
This adjusts this temporal, adding according to the rules of the specified amount.
The amount is typically a Some example code indicating how and why this method is used: date = date.plus(period); // add a Period instance date = date.plus(duration); // add a Duration instance date = date.plus(workingDays(6)); // example user-written workingDays method
Note that calling
|
plus | back to summary |
---|---|
public JapaneseDate plus(long amountToAdd, TemporalUnit unit) Overrides java. Overrides default java. Implements java. Doc from java. Returns an object of the same type as this object with the specified period added.
This method returns a new object based on this one with the specified period added.
For example, on a In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then adding one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
|
plusDays | back to summary |
---|---|
pack-priv JapaneseDate plusDays(long days) Implements abstract java. Doc from java. Returns a copy of this date with the specified number of days added. This adds the specified period in days to the date. This instance is immutable and unaffected by this method call.
|
plusMonths | back to summary |
---|---|
pack-priv JapaneseDate plusMonths(long months) Implements abstract java. Doc from java. Returns a copy of this date with the specified number of months added. This adds the specified period in months to the date. In some cases, adding months can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month. This instance is immutable and unaffected by this method call.
|
plusWeeks | back to summary |
---|---|
pack-priv JapaneseDate plusWeeks(long weeksToAdd) Overrides java. Doc from java. Returns a copy of this date with the specified number of weeks added. This adds the specified period in weeks to the date. In some cases, adding weeks can cause the resulting date to become invalid. If this occurs, then other fields will be adjusted to ensure that the result is valid.
The default implementation uses This instance is immutable and unaffected by this method call.
|
plusYears | back to summary |
---|---|
pack-priv JapaneseDate plusYears(long years) Implements abstract java. Doc from java. Returns a copy of this date with the specified number of years added. This adds the specified period in years to the date. In some cases, adding years can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month. This instance is immutable and unaffected by this method call.
|
range | back to summary |
---|---|
public ValueRange range(TemporalField field) Overrides default java. Doc from java. Gets the range of valid values for the specified field.
All fields can be expressed as a Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
|
readExternal | back to summary |
---|---|
pack-priv static JapaneseDate readExternal(DataInput in) throws IOException |
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws InvalidObjectException Defend against malicious streams.
|
toEpochDay | back to summary |
---|---|
public long toEpochDay() Overrides default java. Doc from java. Converts this date to the Epoch Day.
The
This default implementation queries the
|
toPrivateJapaneseDate | back to summary |
---|---|
private static LocalGregorianCalendar. Returns a
|
until | back to summary |
---|---|
public ChronoPeriod until(ChronoLocalDate endDate) Implements java. Doc from java. Calculates the period between this date and another date as a
This calculates the period between two dates. All supplied chronologies
calculate the period using years, months and days, however the
The start and end points are The calculation is performed using the chronology of this date. If necessary, the input date will be converted to match. This instance is immutable and unaffected by this method call.
|
with | back to summary |
---|---|
public JapaneseDate with(TemporalField field, long newValue) Overrides java. Overrides default java. Implements java. Doc from java. Returns an object of the same type as this object with the specified field altered.
This returns a new object based on this one with the value for the specified field changed.
For example, on a In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then changing the month to February would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
|
with | back to summary |
---|---|
public JapaneseDate with(TemporalAdjuster adjuster) Overrides java. Overrides default java. Doc from java. Returns an adjusted object of the same type as this object with the adjustment made.
This adjusts this date-time according to the rules of the specified adjuster.
A simple adjuster might simply set the one of the fields, such as the year field.
A more complex adjuster might set the date to the last day of the month.
A selection of common adjustments is provided in
Some example code indicating how and why this method is used: date = date.with(Month.JULY); // most key classes implement TemporalAdjuster date = date.with(lastDayOfMonth()); // static import from Adjusters date = date.with(next(WEDNESDAY)); // static import from Adjusters and DayOfWeek
|
with | back to summary |
---|---|
private JapaneseDate with(LocalDate newDate) |
withYear | back to summary |
---|---|
private JapaneseDate withYear(JapaneseEra era, int yearOfEra) Returns a copy of this date with the year altered. This method changes the year of the date. If the month-day is invalid for the year, then the previous valid day will be selected instead. This instance is immutable and unaffected by this method call.
|
withYear | back to summary |
---|---|
private JapaneseDate withYear(int year) Returns a copy of this date with the year-of-era altered. This method changes the year-of-era of the date. If the month-day is invalid for the year, then the previous valid day will be selected instead. This instance is immutable and unaffected by this method call.
|
writeExternal | back to summary |
---|---|
pack-priv void writeExternal(DataOutput out) throws IOException |
writeReplace | back to summary |
---|---|
private Object writeReplace() Writes the object using a dedicated serialized form. |