src/java.base/share/classes/java/time/OffsetDateTime.java
changeset 57733 be8c11fc16bb
parent 52078 4a63197816ce
child 57956 e0b8b019d2f5
equal deleted inserted replaced
57732:23e13076e102 57733:be8c11fc16bb
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1652      */
  1652      */
  1653     @Override
  1653     @Override
  1654     public long until(Temporal endExclusive, TemporalUnit unit) {
  1654     public long until(Temporal endExclusive, TemporalUnit unit) {
  1655         OffsetDateTime end = OffsetDateTime.from(endExclusive);
  1655         OffsetDateTime end = OffsetDateTime.from(endExclusive);
  1656         if (unit instanceof ChronoUnit) {
  1656         if (unit instanceof ChronoUnit) {
  1657             end = end.withOffsetSameInstant(offset);
  1657             OffsetDateTime start = this;
  1658             return dateTime.until(end.dateTime, unit);
  1658             try {
       
  1659                 end = end.withOffsetSameInstant(offset);
       
  1660             } catch (DateTimeException ex) {
       
  1661                 // end may be out of valid range. Adjust to end's offset.
       
  1662                 start = withOffsetSameInstant(end.offset);
       
  1663             }
       
  1664             return start.dateTime.until(end.dateTime, unit);
  1659         }
  1665         }
  1660         return unit.between(this, end);
  1666         return unit.between(this, end);
  1661     }
  1667     }
  1662 
  1668 
  1663     /**
  1669     /**