49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
54 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
56 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
57 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
58 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
59 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
60 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62 package java.time.chrono;
63
64 import static java.time.temporal.ChronoField.INSTANT_SECONDS;
65 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
66 import static java.time.temporal.ChronoUnit.FOREVER;
67 import static java.time.temporal.ChronoUnit.NANOS;
68
69 import java.time.DateTimeException;
70 import java.time.Instant;
71 import java.time.LocalTime;
72 import java.time.ZoneId;
73 import java.time.ZoneOffset;
74 import java.time.ZonedDateTime;
75 import java.time.format.DateTimeFormatter;
76 import java.time.temporal.ChronoField;
77 import java.time.temporal.ChronoUnit;
78 import java.time.temporal.Temporal;
79 import java.time.temporal.TemporalAccessor;
80 import java.time.temporal.TemporalAdjuster;
81 import java.time.temporal.TemporalAmount;
82 import java.time.temporal.TemporalField;
83 import java.time.temporal.TemporalQueries;
84 import java.time.temporal.TemporalQuery;
85 import java.time.temporal.TemporalUnit;
86 import java.time.temporal.UnsupportedTemporalTypeException;
87 import java.time.temporal.ValueRange;
88 import java.util.Comparator;
120 */
121 public interface ChronoZonedDateTime<D extends ChronoLocalDate>
122 extends Temporal, Comparable<ChronoZonedDateTime<?>> {
123
124 /**
125 * Gets a comparator that compares {@code ChronoZonedDateTime} in
126 * time-line order ignoring the chronology.
127 * <p>
128 * This comparator differs from the comparison in {@link #compareTo} in that it
129 * only compares the underlying instant and not the chronology.
130 * This allows dates in different calendar systems to be compared based
131 * on the position of the date-time on the instant time-line.
132 * The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
133 *
134 * @return a comparator that compares in time-line order ignoring the chronology
135 * @see #isAfter
136 * @see #isBefore
137 * @see #isEqual
138 */
139 static Comparator<ChronoZonedDateTime<?>> timeLineOrder() {
140 return AbstractChronology.INSTANT_ORDER;
141 }
142
143 //-----------------------------------------------------------------------
144 /**
145 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
146 * <p>
147 * This creates a zoned date-time based on the specified temporal.
148 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
149 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
150 * <p>
151 * The conversion extracts and combines the chronology, date, time and zone
152 * from the temporal object. The behavior is equivalent to using
153 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
154 * Implementations are permitted to perform optimizations such as accessing
155 * those fields that are equivalent to the relevant objects.
156 * <p>
157 * This method matches the signature of the functional interface {@link TemporalQuery}
158 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
159 *
160 * @param temporal the temporal object to convert, not null
|
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
54 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
56 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
57 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
58 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
59 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
60 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62 package java.time.chrono;
63
64 import static java.time.temporal.ChronoField.INSTANT_SECONDS;
65 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
66 import static java.time.temporal.ChronoUnit.FOREVER;
67 import static java.time.temporal.ChronoUnit.NANOS;
68
69 import java.io.Serializable;
70 import java.time.DateTimeException;
71 import java.time.Instant;
72 import java.time.LocalTime;
73 import java.time.ZoneId;
74 import java.time.ZoneOffset;
75 import java.time.ZonedDateTime;
76 import java.time.format.DateTimeFormatter;
77 import java.time.temporal.ChronoField;
78 import java.time.temporal.ChronoUnit;
79 import java.time.temporal.Temporal;
80 import java.time.temporal.TemporalAccessor;
81 import java.time.temporal.TemporalAdjuster;
82 import java.time.temporal.TemporalAmount;
83 import java.time.temporal.TemporalField;
84 import java.time.temporal.TemporalQueries;
85 import java.time.temporal.TemporalQuery;
86 import java.time.temporal.TemporalUnit;
87 import java.time.temporal.UnsupportedTemporalTypeException;
88 import java.time.temporal.ValueRange;
89 import java.util.Comparator;
121 */
122 public interface ChronoZonedDateTime<D extends ChronoLocalDate>
123 extends Temporal, Comparable<ChronoZonedDateTime<?>> {
124
125 /**
126 * Gets a comparator that compares {@code ChronoZonedDateTime} in
127 * time-line order ignoring the chronology.
128 * <p>
129 * This comparator differs from the comparison in {@link #compareTo} in that it
130 * only compares the underlying instant and not the chronology.
131 * This allows dates in different calendar systems to be compared based
132 * on the position of the date-time on the instant time-line.
133 * The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
134 *
135 * @return a comparator that compares in time-line order ignoring the chronology
136 * @see #isAfter
137 * @see #isBefore
138 * @see #isEqual
139 */
140 static Comparator<ChronoZonedDateTime<?>> timeLineOrder() {
141 return (Comparator<ChronoZonedDateTime<?>> & Serializable) (dateTime1, dateTime2) -> {
142 int cmp = Long.compare(dateTime1.toEpochSecond(), dateTime2.toEpochSecond());
143 if (cmp == 0) {
144 cmp = Long.compare(dateTime1.toLocalTime().getNano(), dateTime2.toLocalTime().getNano());
145 }
146 return cmp;
147 };
148 }
149
150 //-----------------------------------------------------------------------
151 /**
152 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
153 * <p>
154 * This creates a zoned date-time based on the specified temporal.
155 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
156 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
157 * <p>
158 * The conversion extracts and combines the chronology, date, time and zone
159 * from the temporal object. The behavior is equivalent to using
160 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
161 * Implementations are permitted to perform optimizations such as accessing
162 * those fields that are equivalent to the relevant objects.
163 * <p>
164 * This method matches the signature of the functional interface {@link TemporalQuery}
165 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
166 *
167 * @param temporal the temporal object to convert, not null
|