90 * <p> |
90 * <p> |
91 * This class stores all date and time fields, to a precision of nanoseconds. |
91 * This class stores all date and time fields, to a precision of nanoseconds. |
92 * It does not store or represent a time-zone. For example, the value |
92 * It does not store or represent a time-zone. For example, the value |
93 * "2nd October 2007 at 13:45.30.123456789" can be stored in an {@code ChronoLocalDateTime}. |
93 * "2nd October 2007 at 13:45.30.123456789" can be stored in an {@code ChronoLocalDateTime}. |
94 * |
94 * |
95 * <h3>Specification for implementors</h3> |
95 * @implSpec |
96 * This class is immutable and thread-safe. |
96 * This class is immutable and thread-safe. |
97 * |
97 * |
98 * @param <D> the concrete type for the date of this date-time |
98 * @param <D> the concrete type for the date of this date-time |
99 * @since 1.8 |
99 * @since 1.8 |
100 */ |
100 */ |
351 |
351 |
352 //----------------------------------------------------------------------- |
352 //----------------------------------------------------------------------- |
353 @Override |
353 @Override |
354 public long periodUntil(Temporal endDateTime, TemporalUnit unit) { |
354 public long periodUntil(Temporal endDateTime, TemporalUnit unit) { |
355 if (endDateTime instanceof ChronoLocalDateTime == false) { |
355 if (endDateTime instanceof ChronoLocalDateTime == false) { |
356 throw new DateTimeException("Unable to calculate period between objects of two different types"); |
356 throw new DateTimeException("Unable to calculate amount as objects are of two different types"); |
357 } |
357 } |
358 @SuppressWarnings("unchecked") |
358 @SuppressWarnings("unchecked") |
359 ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) endDateTime; |
359 ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) endDateTime; |
360 if (toLocalDate().getChronology().equals(end.toLocalDate().getChronology()) == false) { |
360 if (toLocalDate().getChronology().equals(end.toLocalDate().getChronology()) == false) { |
361 throw new DateTimeException("Unable to calculate period between two different chronologies"); |
361 throw new DateTimeException("Unable to calculate amount as objects have different chronologies"); |
362 } |
362 } |
363 if (unit instanceof ChronoUnit) { |
363 if (unit instanceof ChronoUnit) { |
364 ChronoUnit f = (ChronoUnit) unit; |
364 ChronoUnit f = (ChronoUnit) unit; |
365 if (f.isTimeUnit()) { |
365 if (f.isTimeUnit()) { |
366 long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); |
366 long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); |