jdk/src/share/classes/java/time/chrono/ChronoZonedDateTimeImpl.java
changeset 17474 8c100beabcc0
parent 16852 60207b2b4b42
child 19030 32f129cb6351
equal deleted inserted replaced
17473:35cd9b3a98ff 17474:8c100beabcc0
    93  * <p>
    93  * <p>
    94  * The purpose of storing the time-zone is to distinguish the ambiguous case where
    94  * The purpose of storing the time-zone is to distinguish the ambiguous case where
    95  * the local time-line overlaps, typically as a result of the end of daylight time.
    95  * the local time-line overlaps, typically as a result of the end of daylight time.
    96  * Information about the local-time can be obtained using methods on the time-zone.
    96  * Information about the local-time can be obtained using methods on the time-zone.
    97  *
    97  *
    98  * <h3>Specification for implementors</h3>
    98  * @implSpec
    99  * This class is immutable and thread-safe.
    99  * This class is immutable and thread-safe.
   100  *
   100  *
   101  * @param <D> the concrete type for the date of this date-time
   101  * @param <D> the concrete type for the date of this date-time
   102  * @since 1.8
   102  * @since 1.8
   103  */
   103  */
   285 
   285 
   286     //-----------------------------------------------------------------------
   286     //-----------------------------------------------------------------------
   287     @Override
   287     @Override
   288     public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
   288     public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
   289         if (endDateTime instanceof ChronoZonedDateTime == false) {
   289         if (endDateTime instanceof ChronoZonedDateTime == false) {
   290             throw new DateTimeException("Unable to calculate period between objects of two different types");
   290             throw new DateTimeException("Unable to calculate amount as objects are of two different types");
   291         }
   291         }
   292         @SuppressWarnings("unchecked")
   292         @SuppressWarnings("unchecked")
   293         ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) endDateTime;
   293         ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) endDateTime;
   294         if (toLocalDate().getChronology().equals(end.toLocalDate().getChronology()) == false) {
   294         if (toLocalDate().getChronology().equals(end.toLocalDate().getChronology()) == false) {
   295             throw new DateTimeException("Unable to calculate period between two different chronologies");
   295             throw new DateTimeException("Unable to calculate amount as objects have different chronologies");
   296         }
   296         }
   297         if (unit instanceof ChronoUnit) {
   297         if (unit instanceof ChronoUnit) {
   298             end = end.withZoneSameInstant(offset);
   298             end = end.withZoneSameInstant(offset);
   299             return dateTime.periodUntil(end.toLocalDateTime(), unit);
   299             return dateTime.periodUntil(end.toLocalDateTime(), unit);
   300         }
   300         }