128 * {@code Chronology} must be registered as a Service implementing the {@code Chronology} interface |
128 * {@code Chronology} must be registered as a Service implementing the {@code Chronology} interface |
129 * in the {@code META-INF/Services} file as per the specification of {@link java.util.ServiceLoader}. |
129 * in the {@code META-INF/Services} file as per the specification of {@link java.util.ServiceLoader}. |
130 * The subclass must function according to the {@code Chronology} class description and must provide its |
130 * The subclass must function according to the {@code Chronology} class description and must provide its |
131 * {@link java.time.chrono.Chronology#getId() chronlogy ID} and {@link Chronology#getCalendarType() calendar type}. </p> |
131 * {@link java.time.chrono.Chronology#getId() chronlogy ID} and {@link Chronology#getCalendarType() calendar type}. </p> |
132 * |
132 * |
133 * <h3>Specification for implementors</h3> |
133 * @implSpec |
134 * This abstract class must be implemented with care to ensure other classes operate correctly. |
134 * This abstract class must be implemented with care to ensure other classes operate correctly. |
135 * All implementations that can be instantiated must be final, immutable and thread-safe. |
135 * All implementations that can be instantiated must be final, immutable and thread-safe. |
136 * Subclasses should be Serializable wherever possible. |
136 * Subclasses should be Serializable wherever possible. |
137 * |
137 * |
138 * @param <D> the ChronoLocalDate of this date-time |
138 * @param <D> the ChronoLocalDate of this date-time |
323 @Override |
323 @Override |
324 public long periodUntil(Temporal endDateTime, TemporalUnit unit) { |
324 public long periodUntil(Temporal endDateTime, TemporalUnit unit) { |
325 Objects.requireNonNull(endDateTime, "endDateTime"); |
325 Objects.requireNonNull(endDateTime, "endDateTime"); |
326 Objects.requireNonNull(unit, "unit"); |
326 Objects.requireNonNull(unit, "unit"); |
327 if (endDateTime instanceof ChronoLocalDate == false) { |
327 if (endDateTime instanceof ChronoLocalDate == false) { |
328 throw new DateTimeException("Unable to calculate period between objects of two different types"); |
328 throw new DateTimeException("Unable to calculate amount as objects are of two different types"); |
329 } |
329 } |
330 ChronoLocalDate<?> end = (ChronoLocalDate<?>) endDateTime; |
330 ChronoLocalDate<?> end = (ChronoLocalDate<?>) endDateTime; |
331 if (getChronology().equals(end.getChronology()) == false) { |
331 if (getChronology().equals(end.getChronology()) == false) { |
332 throw new DateTimeException("Unable to calculate period between two different chronologies"); |
332 throw new DateTimeException("Unable to calculate amount as objects have different chronologies"); |
333 } |
333 } |
334 if (unit instanceof ChronoUnit) { |
334 if (unit instanceof ChronoUnit) { |
335 switch ((ChronoUnit) unit) { |
335 switch ((ChronoUnit) unit) { |
336 case DAYS: return daysUntil(end); |
336 case DAYS: return daysUntil(end); |
337 case WEEKS: return daysUntil(end) / 7; |
337 case WEEKS: return daysUntil(end) / 7; |