Creates an instance.
Returns a copy of this date with the specified number of days subtracted. !(p) This subtracts the specified period _in days to the date. !(p) The default implementation uses {@link #plusDays(long)}. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of months subtracted. !(p) 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. !(p) The default implementation uses {@link #plusMonths(long)}. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of weeks subtracted. !(p) 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. !(p) The default implementation uses {@link #plusWeeks(long)}. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of years subtracted. !(p) 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. !(p) The default implementation uses {@link #plusYears(long)}. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of days added. !(p) This adds the specified period _in days to the date. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of months added. !(p) 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. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of weeks added. !(p) 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. !(p) The default implementation uses {@link #plusDays(long)} using a 7 day week. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this date with the specified number of years added. !(p) 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. !(p) This instance is immutable and unaffected by this method call.
Casts the {@code Temporal} to {@code ChronoLocalDate} ensuring it bas the specified chronology.
Gets a comparator that compares {@code ChronoLocalDate} _in time-line order ignoring the chronology. !(p) This comparator differs from the comparison _in {@link #compareTo} _in that it only compares the underlying date and not the chronology. This allows dates _in different calendar systems to be compared based on the position of the date on the local time-line. The underlying comparison is equivalent to comparing the epoch-day.
Obtains an instance of {@code ChronoLocalDate} from a temporal object. !(p) This obtains a local date based on the specified temporal. A {@code TemporalAccessor} represents an arbitrary set of date and time information, which this factory converts to an instance of {@code ChronoLocalDate}. !(p) The conversion extracts and combines the chronology and the date from the temporal object. The behavior is equivalent to using {@link Chronology#date(TemporalAccessor)} with the extracted chronology. Implementations are permitted to perform optimizations such as accessing those fields that are equivalent to the relevant objects. !(p) This method matches the signature of the functional interface {@link TemporalQuery} allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
Gets the chronology of this date. !(p) The {@code Chronology} represents the calendar system _in use. The era and other fields _in {@link ChronoField} are defined by the chronology.
Gets the era, as defined by the chronology. !(p) The era is, conceptually, the largest division of the time-line. Most calendar systems have a single epoch dividing the time-line into two eras. However, some have multiple eras, such as one for the reign of each leader. The exact meaning is determined by the {@code Chronology}. !(p) All correctly implemented {@code Era} classes are singletons, thus it is valid code to write {@code date.getEra() == SomeChrono.ERA_NAME)}. !(p) This implementation uses {@link Chronology#eraOf(int)}.
Checks if the year is a leap year, as defined by the calendar system. !(p) A leap-year is a year of a longer length than normal. The exact meaning is determined by the chronology with the constraint that a leap-year must imply a year-length longer than a non leap-year. !(p) This implementation uses {@link Chronology#isLeapYear(long)}.
Returns the length of the month represented by this date, as defined by the calendar system. !(p) This returns the length of the month _in days.
Returns the length of the year represented by this date, as defined by the calendar system. !(p) This returns the length of the year _in days. !(p) The implementation uses {@link #isLeapYear()} and returns 365 or 366.
Checks if the specified field is supported. !(p) This checks if the specified field can be queried on this date. If false, then calling the {@link #range(TemporalField) range}, {@link #get(TemporalField) get} and {@link #_with(TemporalField, long)} methods will throw an exception. !(p) The set of supported fields is defined by the chronology and normally includes all {@code ChronoField} date fields. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} passing {@code this} as the argument. Whether the field is supported is determined by the field.
Checks if the specified unit is supported. !(p) This checks if the specified unit can be added to or subtracted from this date. If false, then calling the {@link #plus(long, TemporalUnit)} and {@link #minus(long, TemporalUnit) minus} methods will throw an exception. !(p) The set of supported units is defined by the chronology and normally includes all {@code ChronoUnit} date units except {@code FOREVER}. !(p) If the unit is not a {@code ChronoUnit}, then the result of this method is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} passing {@code this} as the argument. Whether the unit is supported is determined by the unit.
{@inheritDoc} @throws DateTimeException {@inheritDoc} @throws ArithmeticException {@inheritDoc}
{@inheritDoc} @throws DateTimeException {@inheritDoc} @throws UnsupportedTemporalTypeException {@inheritDoc} @throws ArithmeticException {@inheritDoc}
{@inheritDoc} @throws DateTimeException {@inheritDoc} @throws ArithmeticException {@inheritDoc}
{@inheritDoc} @throws DateTimeException {@inheritDoc} @throws ArithmeticException {@inheritDoc}
{@inheritDoc} @throws DateTimeException {@inheritDoc} @throws ArithmeticException {@inheritDoc}
{@inheritDoc} @throws DateTimeException {@inheritDoc} @throws UnsupportedTemporalTypeException {@inheritDoc} @throws ArithmeticException {@inheritDoc}
Queries this date using the specified query. !(p) This queries this date using the specified query strategy object. The {@code TemporalQuery} object defines the logic to be used to obtain the result. Read the documentation of the query to understand what the result of this method will be. !(p) The result of this method is obtained by invoking the {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the specified query passing {@code this} as the argument.
Adjusts the specified temporal object to have the same date as this object. !(p) This returns a temporal object of the same observable type as the input with the date changed to be the same as this. !(p) The adjustment is equivalent to using {@link Temporal#_with(TemporalField, long)} passing {@link ChronoField#EPOCH_DAY} as the field. !(p) In most cases, it is clearer to reverse the calling pattern by using {@link Temporal#_with(TemporalAdjuster)}: !(pre) // these two lines are equivalent, but the second approach is recommended temporal = thisLocalDate.adjustInto(temporal); temporal = temporal._with(thisLocalDate); </pre> !(p) This instance is immutable and unaffected by this method call.
Calculates the amount of time until another date _in terms of the specified unit. !(p) This calculates the amount of time between two {@code ChronoLocalDate} objects _in terms of a single {@code TemporalUnit}. The start and end points are {@code this} and the specified date. The result will be negative if the end is before the start. The {@code Temporal} passed to this method is converted to a {@code ChronoLocalDate} using {@link Chronology#date(TemporalAccessor)}. The calculation returns a whole number, representing the number of complete units between the two dates. For example, the amount _in days between two dates can be calculated using {@code startDate.until(endDate, DAYS)}. !(p) There are two equivalent ways of using this method. The first is to invoke this method. The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: !(pre) // these two lines are equivalent amount = start.until(end, MONTHS); amount = MONTHS.between(start, end); </pre> The choice should be made based on which makes the code more readable. !(p) The calculation is implemented _in this method for {@link ChronoUnit}. The units {@code DAYS}, {@code WEEKS}, {@code MONTHS}, {@code YEARS}, {@code DECADES}, {@code CENTURIES}, {@code MILLENNIA} and {@code ERAS} should be supported by all implementations. Other {@code ChronoUnit} values will throw an exception. !(p) If the unit is not a {@code ChronoUnit}, then the result of this method is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} passing {@code this} as the first argument and the converted input temporal as the second argument. !(p) This instance is immutable and unaffected by this method call.
Calculates the period between this date and another date as a {@code ChronoPeriod}. !(p) This calculates the period between two dates. All supplied chronologies calculate the period using years, months and days, however the {@code ChronoPeriod} API allows the period to be represented using other units. !(p) The start and end points are {@code this} and the specified date. The result will be negative if the end is before the start. The negative sign will be the same _in each of year, month and day. !(p) The calculation is performed using the chronology of this date. If necessary, the input date will be converted to match. !(p) This instance is immutable and unaffected by this method call.
Combines this date with a time to create a {@code ChronoLocalDateTime}. !(p) This returns a {@code ChronoLocalDateTime} formed from this date at the specified time. All possible combinations of date and time are valid.
Converts this date to the Epoch Day. !(p) The {@link ChronoField#EPOCH_DAY Epoch Day count} is a simple incrementing count of days where day 0 is 1970-01-01 (ISO). This definition is the same for all chronologies, enabling conversion. !(p) This implementation queries the {@code EPOCH_DAY} field.
Compares this date to another date, including the chronology. !(p) The comparison is based first on the underlying time-line date, then on the chronology. It is "consistent with equals", as defined by {@link Comparable}. !(p) For example, the following is the comparator order: !(ol) !(li){@code 2012-12-03 (ISO)}</li> !(li){@code 2012-12-04 (ISO)}</li> !(li){@code 2555-12-04 (ThaiBuddhist)}</li> !(li){@code 2012-12-05 (ISO)}</li> </ol> Values #2 and #3 represent the same date on the time-line. When two values represent the same date, the chronology ID is compared to distinguish them. This step is needed to make the ordering "consistent with equals". !(p) If all the date objects being compared are _in the same chronology, then the additional chronology stage is not required and only the local date is used. To compare the dates of two {@code TemporalAccessor} instances, including dates _in two different chronologies, use {@link ChronoField#EPOCH_DAY} as a comparator. !(p) This implementation performs the comparison defined above.
Checks if this date is after the specified date ignoring the chronology. !(p) This method differs from the comparison _in {@link #compareTo} _in that it only compares the underlying date and not the chronology. This allows dates _in different calendar systems to be compared based on the time-line position. This is equivalent to using {@code date1.toEpochDay() > date2.toEpochDay()}. !(p) This implementation performs the comparison based on the epoch-day.
Checks if this date is before the specified date ignoring the chronology. !(p) This method differs from the comparison _in {@link #compareTo} _in that it only compares the underlying date and not the chronology. This allows dates _in different calendar systems to be compared based on the time-line position. This is equivalent to using {@code date1.toEpochDay() < date2.toEpochDay()}. !(p) This implementation performs the comparison based on the epoch-day.
Checks if this date is equal to the specified date ignoring the chronology. !(p) This method differs from the comparison _in {@link #compareTo} _in that it only compares the underlying date and not the chronology. This allows dates _in different calendar systems to be compared based on the time-line position. This is equivalent to using {@code date1.toEpochDay() == date2.toEpochDay()}. !(p) This implementation performs the comparison based on the epoch-day.
Checks if this date is equal to another date, including the chronology. !(p) Compares this date with another ensuring that the date and chronology are the same. !(p) To compare the dates of two {@code TemporalAccessor} instances, including dates _in two different chronologies, use {@link ChronoField#EPOCH_DAY} as a comparator.
A hash code for this date.
Outputs this date as a {@code string}. !(p) The output will include the full local date.
Checks if the specified unit is supported. !(p) This checks if the specified unit can be added to, or subtracted from, this date-time. If false, then calling the {@link #plus(long, TemporalUnit)} and {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
Returns an adjusted object of the same type as this object with the adjustment made. !(p) 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 {@link hunt.time.temporal.TemporalAdjusters TemporalAdjusters}. These include finding the "last day of the month" and "next Wednesday". The adjuster is responsible for handling special cases, such as the varying lengths of month and leap years. !(p) Some example code indicating how and why this method is used: !(pre) 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 </pre>
Returns an object of the same type as this object with the specified field altered. !(p) This returns a new object based on this one with the value for the specified field changed. For example, on a {@code LocalDate}, this could be used to set the year, month or day-of-month. The returned object will have the same observable type as this object. !(p) 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.
Returns an object of the same type as this object with an amount added. !(p) This adjusts this temporal, adding according to the rules of the specified amount. The amount is typically a {@link hunt.time.Period} but may be any other type implementing the {@link TemporalAmount} interface, such as {@link hunt.time.Duration}. !(p) Some example code indicating how and why this method is used: !(pre) 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 </pre> !(p) Note that calling {@code plus} followed by {@code minus} is not guaranteed to return the same date-time.
Returns an object of the same type as this object with the specified period added. !(p) This method returns a new object based on this one with the specified period added. For example, on a {@code LocalDate}, this could be used to add a number of years, months or days. The returned object will have the same observable type as this object. !(p) 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.
Returns an object of the same type as this object with an amount subtracted. !(p) This adjusts this temporal, subtracting according to the rules of the specified amount. The amount is typically a {@link hunt.time.Period} but may be any other type implementing the {@link TemporalAmount} interface, such as {@link hunt.time.Duration}. !(p) Some example code indicating how and why this method is used: !(pre) 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 </pre> !(p) Note that calling {@code plus} followed by {@code minus} is not guaranteed to return the same date-time.
Returns an object of the same type as this object with the specified period subtracted. !(p) This method returns a new object based on this one with the specified period subtracted. For example, on a {@code LocalDate}, this could be used to subtract a number of years, months or days. The returned object will have the same observable type as this object. !(p) 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.
Calculates the amount of time until another temporal _in terms of the specified unit. !(p) This calculates the amount of time between two temporal objects _in terms of a single {@code TemporalUnit}. The start and end points are {@code this} and the specified temporal. The end point is converted to be of the same type as the start point if different. The result will be negative if the end is before the start. For example, the amount _in hours between two temporal objects can be calculated using {@code startTime.until(endTime, HOURS)}. !(p) The calculation returns a whole number, representing the number of complete units between the two temporals. For example, the amount _in hours between the times 11:30 and 13:29 will only be one hour as it is one minute short of two hours. !(p) There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: !(pre) // these two lines are equivalent temporal = start.until(end, unit); temporal = unit.between(start, end); </pre> The choice should be made based on which makes the code more readable. !(p) For example, this method allows the number of days between two dates to be calculated: !(pre) long daysBetween = start.until(end, DAYS); // or alternatively long daysBetween = DAYS.between(start, end); </pre>
Adjusts the specified temporal object. !(p) This adjusts the specified temporal object using the logic encapsulated _in the implementing class. Examples might be an adjuster that sets the date avoiding weekends, or one that sets the date to the last day of the month. !(p) There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use {@link Temporal#_with(TemporalAdjuster)}: !(pre) // these two lines are equivalent, but the second approach is recommended temporal = thisAdjuster.adjustInto(temporal); temporal = temporal._with(thisAdjuster); </pre> It is recommended to use the second approach, {@code _with(TemporalAdjuster)}, as it is a lot clearer to read _in code.
A date expressed _in terms of a standard year-month-day calendar system. !(p) This class is used by applications seeking to handle dates _in non-ISO calendar systems. For example, the Japanese, Minguo, Thai Buddhist and others. !(p) {@code ChronoLocalDate} is built on the generic concepts of year, month and day. The calendar system, represented by a {@link hunt.time.chrono.Chronology}, expresses the relationship between the fields and this class allows the resulting date to be manipulated. !(p) Note that not all calendar systems are suitable for use with this class. For example, the Mayan calendar uses a system that bears no relation to years, months and days. !(p) The API design encourages the use of {@code LocalDate} for the majority of the application. This includes code to read and write from a persistent data store, such as a database, and to send dates and times across a network. The {@code ChronoLocalDate} instance is then used at the user interface level to deal with localized input/output.
!(P)Example: </p> !(pre) System._out.printf("Example()%n"); // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); foreach(Chronology chrono ; chronos) { ChronoLocalDate date = chrono.dateNow(); System._out.printf(" %20s: %s%n", chrono.getID(), date.toString()); }
// Print the Hijrah date and calendar ChronoLocalDate date = Chronology.of("Hijrah").dateNow(); int day = date.get(ChronoField.DAY_OF_MONTH); int dow = date.get(ChronoField.DAY_OF_WEEK); int month = date.get(ChronoField.MONTH_OF_YEAR); int year = date.get(ChronoField.YEAR); System._out.printf(" Today is %s %s %d-%s-%d%n", date.getChronology().getID(), dow, day, month, year);
// Print today's date and the last day of the year ChronoLocalDate now1 = Chronology.of("Hijrah").dateNow(); ChronoLocalDate first = now1._with(ChronoField.DAY_OF_MONTH, 1) ._with(ChronoField.MONTH_OF_YEAR, 1); ChronoLocalDate last = first.plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System._out.printf(" Today is %s: start: %s; end: %s%n", last.getChronology().getID(), first, last); </pre>
!(h3)Adding Calendars</h3> !(p) The set of calendars is extensible by defining a subclass of {@link ChronoLocalDate} to represent a date instance and an implementation of {@code Chronology} to be the factory for the ChronoLocalDate subclass. </p> !(p) To permit the discovery of the additional calendar types the implementation of {@code Chronology} must be registered as a Service implementing the {@code Chronology} interface _in the {@code META-INF/Services} file as per the specification of {@link java.util.ServiceLoader}. The subclass must function according to the {@code Chronology} class description and must provide its {@link hunt.time.chrono.Chronology#getId() chronlogy ID} and {@link Chronology#getCalendarType() calendar type}. </p>
@implSpec This abstract class must be implemented with care to ensure other classes operate correctly. All implementations that can be instantiated must be final, immutable and thread-safe. Subclasses should be Serializable wherever possible.
@param !(D) the ChronoLocalDate of this date-time @since 1.8